Skip to content

fix(dash-spv): time an idle peer from its first request - #1332

Merged
ZocoLini merged 1 commit into
devfrom
fix/idle-peer-kick-on-first-request
Nov 5, 2026
Merged

ZocoLini merged 1 commit into
devfrom
fix/idle-peer-kick-on-first-request

Conversation

@xdustinface

@xdustinface xdustinface commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1329.

Problem

The timeout monitor flags a peer that has bytes in flight and whose byte counter has not risen for request_timeout (10 s minimum). The clock counted from the last byte the peer sent, not from when it was given work. At the chain tip a peer is often quiet for more than 10 s, so the first request sent to it got it kicked and banned at the next one second check.

A testnet run showed two such kicks, 60 to 160 ms after the send. Both peers had nothing in flight before the request, so this is not the leaked charge from #1219:

11:04:05.346  router: sent 2 | peers=3
11:04:05.503  WARN request timeout: kicked 1 peer(s) {68.67.122.42 ...}, retried 1 request(s)

Fix

The per-peer check in spawn_timeout_monitor also restarts the stall clock on every tick that finds the peer with nothing in flight. The clock therefore starts at the last idle tick before the peer was given work, and a peer that stays silent with work is still kicked about request_timeout after the send. No extra per-peer state is needed. A peer's in-flight charge only drops on an inbound message, which also raises its byte counter, so an idle to busy change between two ticks cannot slip past the check.

broker.expire times each request from its own progress and is unaffected.

Tests

  • the_timeout_monitor_times_an_idle_peer_from_its_first_request admits a loopback peer, leaves it idle for three timeouts, then charges it with a getcfilters. It must still be connected two checks later and be kicked once a further REQUEST_TIMEOUT passes in silence. It never registers the request with the broker, so a kick can only come from the per-peer check. Without the fix it fails with the peer kicked right after its first request.
  • cargo test -p dash-spv --lib: 639 passed (on dev at c9aeac0d0).
  • just dash-spv::test: all green, including dashd_sync 38/38 and dashd_masternode 11/11.

Related: #1228, whose kicked peers had also stopped sending 10 to 18 s before the kick. This fix may explain part of it, but other causes there are not ruled out.

PR Hygiene · 1291b11

  • Bots — coderabbitai ✓
  • Self-review — posted; again after any push
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Peers remain connected during idle periods before they receive their first request, rather than having that silence count toward a timeout.
    • When a request is in progress, peers are disconnected if they make no byte-level progress for longer than the request timeout, adjusted for lag. This keeps timeout behavior tied to activity during active work.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The peer timeout monitor now starts measuring silence when a peer has in-flight work, rather than counting silence from before work was assigned. A paused-time test covers an idle peer that later receives work.

Changes: Peer timeout tracking

Layer / File(s) Summary
Timeout tracking and regression test
dash-spv/src/network/manager.rs
The monitor resets its liveness timestamp when the peer is idle or its byte count increases. It applies the peer-level timeout only while work is in flight. A paused-time test checks that a peer remains connected after receiving work following a long idle period, then disconnects after a further timeout period.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zocolini, pastapastapasta

Merge Risk: Low · up to 1291b

A peer with a fractional lag-adjusted timeout could be disconnected and temporarily banned slightly early. The narrow timing window makes this a bounded risk rather than a merge blocker.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: the timeout clock for an idle peer starts from its first request, in dash-spv. The raw summary and objectives both describe a timeout monitor that resets the progress times…
Linked Issues check Passed Issue #1329 requires preventing a healthy idle peer from being kicked on its first request. In dash-spv/src/network/manager.rs, the timeout monitor resets the per-peer progress timestamp when `in_fl…
Out of Scope Changes check Passed The diff changes only the timeout monitor documentation and logic in dash-spv/src/network/manager.rs, plus a focused regression test for issue #1329. These changes directly support the linked issue.…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the change: the timeout clock for an idle peer starts from its first request, in dash-spv. The raw summary and objectives both describe a timeout monitor that resets the progress timestamp for idle peers, so the title matches the main change. It follows the conventional commit form and is specific enough for a teammate scanning history.

Full details: Linked Issues check

Explanation

Issue #1329 requires preventing a healthy idle peer from being kicked on its first request. In dash-spv/src/network/manager.rs, the timeout monitor resets the per-peer progress timestamp when in_flight == 0, then applies the timeout only while work is in flight. The added the_timeout_monitor_times_an_idle_peer_from_its_first_request test verifies that an idle peer remains connected after its first request and is kicked only after a further timeout in silence. This implementation meets the issue behavior without requiring the issue's proposed state-transition implementation.

Full details: Out of Scope Changes check

Explanation

The diff changes only the timeout monitor documentation and logic in dash-spv/src/network/manager.rs, plus a focused regression test for issue #1329. These changes directly support the linked issue. No unrelated production behavior or unrelated tests are present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c9aeac0 and 1291b11.

Files selected for processing: 1

  • dash-spv/src/network/manager.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.16%. Comparing base (c9aeac0) to head (1291b11).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1332   +/-   ##
=======================================
  Coverage   85.16%   85.16%           
=======================================
  Files         268      268           
  Lines       68085    68105   +20     
=======================================
+ Hits        57983    58005   +22     
+ Misses      10102    10100    -2     
Flag Coverage Δ
core 82.43% <ø> (ø)
rpc 52.10% <ø> (ø)
spv 94.01% <100.00%> (+0.01%) ⬆️
wallet 83.13% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/network/manager.rs 87.40% <100.00%> (+0.58%) ⬆️

... and 2 files with indirect coverage changes

The timeout monitor flagged a peer with in-flight bytes whose byte counter had not risen for `request_timeout`, counting from the last byte it sent. A peer that stayed quiet at the tip for more than that was kicked and banned at the first check after it was given work.

The stall clock now restarts on every check that finds the peer idle, so it counts from when the peer was given work. A peer that stays silent with work is still kicked after the full timeout.
@xdustinface
xdustinface force-pushed the fix/idle-peer-kick-on-first-request branch from 6adff5f to 1291b11 Compare November 5, 2026 12:25
@xdustinface
xdustinface marked this pull request as ready for review November 5, 2026 12:36
@xdustinface

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 5, 2026
@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Nov 5, 2026
@xdustinface
xdustinface requested a review from ZocoLini November 5, 2026 12:53
@ZocoLini
ZocoLini merged commit 4e49ea9 into dev Nov 5, 2026
42 of 44 checks passed
@ZocoLini
ZocoLini deleted the fix/idle-peer-kick-on-first-request branch November 5, 2026 13:36
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.

dash-spv: an idle peer is kicked on the first request it gets

2 participants