fix(p2p,eth): synchronize pair peer teardown - #2325
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
Synchronizes access to the p2p “pair peer” pointer and snapshots it before triggering an async disconnect during peer shutdown, addressing a teardown race that can lead to a nil dereference panic.
Changes:
- Replace direct
Peer.PairPeerfield access with synchronized accessor/mutator helpers. - Snapshot the pair peer before launching the async disconnect in
Peer.run()to avoid nil dereferences. - Add a regression test ensuring
Peer.run()disconnects the paired peer withDiscPairPeerStop.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| p2p/peer.go | Adds mutex-guarded pair-peer accessors and snapshots pair peer before async disconnect on shutdown. |
| p2p/server.go | Uses synchronized pair-peer helpers when tracking/removing peers and validating handshakes. |
| p2p/dial.go | Uses synchronized pair-peer getter in dial eligibility checks. |
| eth/peer.go | Updates eth peer pairing logic to use new synchronized pair-peer setter. |
| p2p/server_test.go | Updates tests to use the new pair-peer accessors. |
| p2p/peer_test.go | Adds coverage that pair peer is disconnected when the primary peer stops. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Guard PairPeer access with synchronized helpers and snapshot the pair before launching async disconnect during peer shutdown. Add regression coverage for pair-peer teardown and keep the existing pair tracking checks using the synchronized accessors.
Proposed changes
Guard PairPeer access with synchronized helpers and snapshot the pair before launching async disconnect during peer shutdown.
Add regression coverage for pair-peer teardown and keep the existing pair tracking checks using the synchronized accessors.
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