Skip to content

fix: ensure PeerDisconnected is emitted on write-path disconnects#435

Merged
xdustinface merged 1 commit intov0.42-devfrom
fix/peer-reader-loop-race
Feb 16, 2026
Merged

fix: ensure PeerDisconnected is emitted on write-path disconnects#435
xdustinface merged 1 commit intov0.42-devfrom
fix/peer-reader-loop-race

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Feb 14, 2026

This fixes flaky failures in some of the integration tests coming soon. When a peer disconnects and the write path (broken pipe) detects it before the read path (EOF), the PeerDisconnected event could be lost entirely. receive_message() returned
ConnectionFailed instead of PeerDisconnected, causing the reader loop to hit the catch-all error handler which slept 1 second before cleanup. During that sleep, the maintenance
loop could silently remove the peer from the pool, preventing the event from ever being emitted.

  • Return PeerDisconnected from receive_message() when connection state is already cleared
  • Remove unnecessary 1-second sleep in the reader loop error handler

Summary by CodeRabbit

  • Bug Fixes
    • Improved network error handling and responsiveness by removing unnecessary delays and refining error classification in disconnect scenarios.

This fixes flaky failures in some of the integration tests coming soon. When a peer disconnects and the write path (broken pipe) detects it before the read path (EOF), the `PeerDisconnected` event could be lost entirely. `receive_message()` returned
  `ConnectionFailed` instead of `PeerDisconnected`, causing the reader loop to hit the catch-all error handler which slept 1 second before cleanup. During that sleep, the maintenance
  loop could silently remove the peer from the pool, preventing the event from ever being emitted.

  - Return `PeerDisconnected` from `receive_message()` when connection state is already cleared
  - Remove unnecessary 1-second sleep in the reader loop error handler
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

Network peer error handling is refined by removing an unnecessary delay in the manager's error path and changing how missing internal reader state is reported in the peer module, aligning disconnection scenarios with a unified error type.

Changes

Cohort / File(s) Summary
Network error handling
dash-spv/src/network/manager.rs, dash-spv/src/network/peer.rs
Removed 1-second delay from peer reader error path; changed missing internal state error from ConnectionFailed to PeerDisconnected for consistency with EOF/disconnection handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A speedy dash through network lanes,
No more delays in error chains,
When readers fade, the state's now clear—
One voice for disconnection here,
Swift fixes make the protocol cheer!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: ensuring PeerDisconnected is emitted on write-path disconnects, which directly aligns with the root cause analysis and changes made.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into v0.42-dev

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/peer-reader-loop-race

No actionable comments were generated in the recent review. 🎉


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xdustinface xdustinface merged commit ef36032 into v0.42-dev Feb 16, 2026
53 checks passed
@xdustinface xdustinface deleted the fix/peer-reader-loop-race branch February 16, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants