fix(eth): make paired peer unregister instance-aware#2351
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes cleanup for “paired” eth peers (two connections sharing the same peer ID) so that removing the secondary connection doesn’t accidentally remove the primary peer or leave a stale pairRw behind. It also adds regression tests to ensure paired-peer cleanup works and that header serving continues after the paired connection drops.
Changes:
- Update
ProtocolManagerpeer removal to unregister by peer instance (not just by ID), and only unregister from the downloader when removing the primary connection. - Extend
peerSetremoval logic to clear pairing state (pairRwandPairPeer) and addUnregisterPeer(*peer)to support instance-based removal. - Add regression tests for paired peer cleanup and for serving block headers after the paired connection disconnects.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
eth/peer.go |
Adds UnregisterPeer(*peer) and clears pairing state during unregister to avoid stale pairRw and incorrect removals. |
eth/handler.go |
Switches removal to instance-based (removePeer(*peer)), adds removePeerByID wrapper for downloader/fetcher callbacks. |
eth/peer_test.go |
Adds a unit test ensuring unregistering a paired instance keeps the primary and clears pair state. |
eth/handler_test.go |
Adds an integration-style test ensuring headers are still served after the paired connection drops. |
f18843c to
4926447
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
eth/peer.go:583
- Same race/tearing risk exists in this code path:
current.pairRw = nil(and the earlierexistPeer.pairRw = p.rwassignment inRegister) are not synchronized with reads inSend*methods. Even if the peerSet lock is held, send paths don’t take that lock, so this doesn’t prevent concurrent access. Consider encapsulating pair-writer access behind atomic load/store helpers or a dedicated lock onpeerto avoid data races and typed-nil panics.
if current == p {
current.pairRw = nil
delete(ps.peers, p.id)
return nil
}
if current.ClearPairPeer(p.Peer) {
p.ClearPairPeer(current.Peer)
current.pairRw = nil
return nil
4926447 to
b862d5a
Compare
b862d5a to
f3fc79e
Compare
f3fc79e to
c85eecf
Compare
92ac72a to
040bff6
Compare
143b44e to
616c64b
Compare
Handle paired eth peer teardown by instance so dropping the secondary connection clears pair state without removing the primary peer from the set. Synchronize pairRw access to avoid torn interface reads during concurrent send and unregister paths, and cover the lifecycle with regression tests.
616c64b to
faf067a
Compare
Proposed changes
Handle paired eth peer teardown by instance so dropping the secondary connection clears pair state without removing the primary peer from the set.
Synchronize pairRw access to avoid torn interface reads during concurrent send and unregister paths, and cover the lifecycle with regression tests.
fix panic:
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that