Просмотр исходного кода

net/inbound_session: Register stop_sub before registering channel on accept.

I think this led to a race condition, where a channel wouldn't clean up
on time. Possibly being triggerred by lilith's pings. Let's see if this
patch helps clean up any hanging channels.
parazyd 3 лет назад
Родитель
Сommit
201173d15f
1 измененных файлов с 13 добавлено и 4 удалено
  1. 13 4
      src/net/session/inbound_session.rs

+ 13 - 4
src/net/session/inbound_session.rs

@@ -27,7 +27,7 @@ use std::collections::HashMap;
 
 use async_std::sync::{Arc, Mutex, Weak};
 use async_trait::async_trait;
-use log::{error, info};
+use log::{debug, error, info};
 use smol::Executor;
 use url::Url;
 
@@ -174,17 +174,26 @@ impl InboundSession {
         channel: ChannelPtr,
         ex: Arc<Executor<'_>>,
     ) -> Result<()> {
-        info!(target: "net::inbound_session", "[P2P] Connected Inbound #{} [{}]", index, channel.address());
-        self.register_channel(channel.clone(), ex.clone()).await?;
+        info!(
+            target: "net::inbound_session::setup_channel",
+            "[P2P] Connected Inbound #{} [{}]", index, channel.address(),
+        );
+
+        let stop_sub = channel.subscribe_stop().await?;
 
+        self.register_channel(channel.clone(), ex.clone()).await?;
         let addr = channel.address().clone();
 
         self.connect_infos.lock().await[index]
             .insert(addr.clone(), InboundInfo { addr: Some(addr.clone()), channel: None });
 
-        let stop_sub = channel.subscribe_stop().await?;
         stop_sub.receive().await;
+        debug!(
+            target: "net::inbound_session::setup_channel()",
+            "Received stop_sub, removing channel from P2P",
+        );
 
+        self.p2p().remove(channel).await;
         self.connect_infos.lock().await[index].remove(&addr);
 
         Ok(())