From da3067f762a3b8fad87986f979c279cf57fd77a9 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sun, 8 Feb 2026 14:45:49 +0100 Subject: [PATCH] fix: disconnect peers after pong timeout Allow other peers to come in instead. I think the timeout of 60s is enough to get rid of them if they fail to pong. --- dash-spv/src/network/manager.rs | 12 ++++++++++-- dash-spv/src/network/peer.rs | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dash-spv/src/network/manager.rs b/dash-spv/src/network/manager.rs index 1f4232cc6..0cb8edef6 100644 --- a/dash-spv/src/network/manager.rs +++ b/dash-spv/src/network/manager.rs @@ -867,7 +867,8 @@ impl PeerNetworkManager { } } - // Send ping to all peers if needed + // Send ping to all peers if needed and disconnect unresponsive ones + let mut peers_to_disconnect = Vec::new(); for (addr, peer) in pool.get_all_peers().await { let mut peer_guard = peer.write().await; if peer_guard.should_ping() { @@ -881,7 +882,14 @@ impl PeerNetworkManager { ).await; } } - peer_guard.cleanup_old_pings(); + let expired = peer_guard.cleanup_old_pings(); + if expired > 0 { + peers_to_disconnect.push(addr); + } + } + for addr in peers_to_disconnect { + log::warn!("Disconnecting peer {} - ping timeout", addr); + pool.remove_peer(&addr).await; } // Only save known peers if not in exclusive mode diff --git a/dash-spv/src/network/peer.rs b/dash-spv/src/network/peer.rs index f12db9456..04b092231 100644 --- a/dash-spv/src/network/peer.rs +++ b/dash-spv/src/network/peer.rs @@ -765,7 +765,8 @@ impl Peer { } /// Clean up old pending pings that haven't received responses. - pub fn cleanup_old_pings(&mut self) { + /// Returns the number of expired pings that were removed. + pub fn cleanup_old_pings(&mut self) -> usize { const PING_TIMEOUT: Duration = Duration::from_secs(60); // 1 minute timeout for pings let now = SystemTime::now(); @@ -777,10 +778,13 @@ impl Peer { } } + let expired_count = expired_nonces.len(); for nonce in expired_nonces { self.pending_pings.remove(&nonce); tracing::warn!("Ping timeout for {} with nonce {}", self.address, nonce); } + + expired_count } /// Get ping/pong statistics.