Explorar el Código

net: remove potential race conditions

1. Shutting down all channels in p2p.stop() is redundant since they will
   be cleaned up by the session shutdown.
2. subscribe_stop().expect(..) could panic in the case that the node we
   are connecting to disconnects at this exact moment (triggering a
   `ChannelStopped` error).
lunar-mining hace 2 años
padre
commit
63a91dde41
Se han modificado 3 ficheros con 2 adiciones y 10 borrados
  1. 0 5
      src/net/p2p.rs
  2. 1 4
      src/net/session/manual_session.rs
  3. 1 1
      src/net/session/outbound_session.rs

+ 0 - 5
src/net/p2p.rs

@@ -153,11 +153,6 @@ impl P2p {
 
     /// Stop the running P2P subsystem
     pub async fn stop(&self) {
-        // Stop all channels
-        for channel in self.hosts.channels().await {
-            channel.stop().await;
-        }
-
         // Stop the sessions
         self.session_manual().stop().await;
         self.session_inbound().stop().await;

+ 1 - 4
src/net/session/manual_session.rs

@@ -173,10 +173,7 @@ impl Slot {
                                 "[P2P] Manual outbound connected [{}]", url,
                             );
 
-                            let stop_sub = channel
-                                .subscribe_stop()
-                                .await
-                                .expect("Channel should not be stopped");
+                            let stop_sub = channel.subscribe_stop().await?;
 
                             // Channel is now connected but not yet setup
 

+ 1 - 1
src/net/session/outbound_session.rs

@@ -335,7 +335,7 @@ impl Slot {
 
             // At this point we've managed to connect.
 
-            let stop_sub = channel.subscribe_stop().await.expect("Channel should not be stopped");
+            let stop_sub = channel.subscribe_stop().await?;
             // Setup new channel
             if let Err(err) =
                 self.session().register_channel(channel.clone(), self.p2p().executor()).await