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

manual_session: fix bug which caused peers to get stuck in Connect state

We must remove a peer from the HostRegistry when we fail to connect to
it in ManualSession, otherwise we will never attempt to reconnect, since
the state transition of Connect-> Connect will fail.
draoi 2 лет назад
Родитель
Сommit
0c23ba0947
2 измененных файлов с 9 добавлено и 4 удалено
  1. 7 3
      src/net/session/manual_session.rs
  2. 2 1
      src/net/session/outbound_session.rs

+ 7 - 3
src/net/session/manual_session.rs

@@ -163,6 +163,10 @@ impl ManualSession {
                                 "[P2P] Unable to connect to manual outbound [{}]: {}",
                                 addr, e,
                             );
+
+                            // Stop tracking this peer, to avoid it getting stuck in the Connect
+                            // state.
+                            self.p2p().hosts().unregister(&addr).await;
                         }
                     }
                 }
@@ -194,9 +198,9 @@ impl ManualSession {
             "[P2P] Suspending manual connection to {} after {} failed attempts",
             addr, attempts,
         );
-        // Stop tracking this address in the HostRegistry.
-        // Otherwise, host will be stuck in the Connect state.
-        self.p2p().hosts().unregister(&addr).await;
+
+        // Mark this peer as Suspend, which sends it to the Refinery for processing.
+        self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).await.unwrap();
 
         Ok(())
     }

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

@@ -464,7 +464,8 @@ impl Slot {
                     self.slot, addr, e
                 );
 
-                // At this point we failed to connect. We'll downgrade this peer now.
+                // At this point we failed to connect. We'll downgrade this peer and
+                // mark its state as Suspend, which sends it to the Refinery for processing.
                 self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey, true, None).await;
 
                 // Notify that channel processing failed