-
Notifications
You must be signed in to change notification settings - Fork 9
fix: disconnect peers after pong timeout #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xdustinface
wants to merge
1
commit into
v0.42-dev
Choose a base branch
from
fix/disconnect-after-pong-timeout
base: v0.42-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connected_peer_countis never decremented for ping-timeout disconnections, causing counter drift.When
pool.remove_peeris called here, the peer reader task will find the peer gone from the pool (Line 354) and break, but sinceremove_peeralready returnedNoneat that point (Line 637), thefetch_subonconnected_peer_count(Line 640) is skipped. Over time the cached counter will overcount connected peers, breakingis_connected()andpeer_count().You should also emit
NetworkEvent::PeerDisconnected/PeersUpdatedhere to keep event consumers in sync, matching the cleanup instart_peer_reader(Lines 638–654).Proposed fix
for addr in peers_to_disconnect { log::warn!("Disconnecting peer {} - ping timeout", addr); - pool.remove_peer(&addr).await; + if pool.remove_peer(&addr).await.is_some() { + connected_peer_count.fetch_sub(1, Ordering::Relaxed); + let count = connected_peer_count.load(Ordering::Relaxed); + let addresses = pool.get_connected_addresses().await; + let best_height = pool.get_best_height().await; + let _ = network_event_sender.send(NetworkEvent::PeerDisconnected { + address: addr, + }); + let _ = network_event_sender.send(NetworkEvent::PeersUpdated { + connected_count: count, + addresses, + best_height, + }); + } }This requires capturing
network_event_senderinto the maintenance loop closure (it isn't currently captured).🤖 Prompt for AI Agents