From 62a39af19ef2e530d2c6f2928899679c5653b992 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Thu, 25 Jul 2024 21:08:59 +0900 Subject: [PATCH] Fix unexpected `Marking peer disconnected in DHT` (#6140) * Don't disconnect peer in DHT if there's an active connection * Merge branch 'unstable' into dont-disconnect-if-active-connection --- beacon_node/lighthouse_network/src/discovery/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/beacon_node/lighthouse_network/src/discovery/mod.rs b/beacon_node/lighthouse_network/src/discovery/mod.rs index 017db26049..865d707495 100644 --- a/beacon_node/lighthouse_network/src/discovery/mod.rs +++ b/beacon_node/lighthouse_network/src/discovery/mod.rs @@ -1166,8 +1166,19 @@ impl Discovery { fn on_dial_failure(&mut self, peer_id: Option, error: &DialError) { if let Some(peer_id) = peer_id { match error { + DialError::Denied { .. } => { + if self.network_globals.peers.read().is_connected(&peer_id) { + // There's an active connection, so we don’t disconnect the peer. + // Lighthouse dials to a peer twice using TCP and QUIC (if QUIC is not + // disabled). Usually, one establishes a connection, and the other fails + // because the peer allows only one connection per peer. + return; + } + // set peer as disconnected in discovery DHT + debug!(self.log, "Marking peer disconnected in DHT"; "peer_id" => %peer_id, "error" => %ClearDialError(error)); + self.disconnect_peer(&peer_id); + } DialError::LocalPeerId { .. } - | DialError::Denied { .. } | DialError::NoAddresses | DialError::Transport(_) | DialError::WrongPeerId { .. } => {