Browse Source

channel: safely shutdown the channel when an error is triggered

draoi 2 years ago
parent
commit
7959d9741c
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/net/channel.rs

+ 4 - 0
src/net/channel.rs

@@ -281,6 +281,8 @@ impl Channel {
                         target: "net::channel::main_receive_loop()",
                         target: "net::channel::main_receive_loop()",
                         "Stopping channel {:?}", self
                         "Stopping channel {:?}", self
                     );
                     );
+                    self.stop().await;
+
                     return Err(Error::ChannelStopped)
                     return Err(Error::ChannelStopped)
                 }
                 }
             };
             };
@@ -301,6 +303,8 @@ impl Channel {
                     // We will reject further connections from this peer
                     // We will reject further connections from this peer
                     self.p2p().hosts().mark_rejected(self.address()).await;
                     self.p2p().hosts().mark_rejected(self.address()).await;
 
 
+                    self.stop().await;
+
                     return Err(Error::ChannelStopped)
                     return Err(Error::ChannelStopped)
                 }
                 }
                 Err(_) => unreachable!("You added a new error in notify()"),
                 Err(_) => unreachable!("You added a new error in notify()"),