Преглед изворни кода

acceptor: return error instead of calling unwrap() on subscribe_stop

unwrap() can panic in the rare case that a node disconnects while we are
in the middle of accepting a connection from it.

In the case that this happens we should instead just exit with an error.
draoi пре 2 година
родитељ
комит
541166162e
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      src/net/acceptor.rs

+ 2 - 1
src/net/acceptor.rs

@@ -140,10 +140,11 @@ impl Acceptor {
                     let channel_ = channel.clone();
                     let channel_ = channel.clone();
                     let cv_ = cv.clone();
                     let cv_ = cv.clone();
                     ex.spawn(async move {
                     ex.spawn(async move {
-                        let stop_sub = channel_.subscribe_stop().await.unwrap();
+                        let stop_sub = channel_.subscribe_stop().await?;
                         stop_sub.receive().await;
                         stop_sub.receive().await;
                         self_.conn_count.fetch_sub(1, SeqCst);
                         self_.conn_count.fetch_sub(1, SeqCst);
                         cv_.notify();
                         cv_.notify();
+                        Ok::<(), crate::Error>(())
                     })
                     })
                     .detach();
                     .detach();