Skip to content

fix(dash-spv): sync on refactor/network-mod churns peers down to zero on an unstable connection #1228

Open

Description

@ZocoLini

Problem

On refactor/network-mod (#902) at 39eef40d, sync degrades badly when the client's own connection is unstable: high idle latency (~700ms RTT), a download rate that swings from tens of Mbit to near zero, and a deep (bufferbloated) queue. It was reported by a teammate on a real connection, and reproduced on mainnet with the same client link shaping as the dash-spv-bench/scenarios/local.3unstable.yml scenario (added in a2eaf53f).

Symptoms

  • When the rate drops, requests sit in the link's queue behind the data already in flight. REQUEST_TIMEOUT (10s) then kicks peers one after another, including peers kicked with retried 0 request(s) whose bytes are simply queued behind others'.
  • While at least one peer is still connected, the supervisor does not refill the set for minutes, even though it is below max_peers and has hundreds of learned addresses. New handshakes go through the same saturated link and either miss CONNECT_DEADLINE or come back over the bad-lag threshold, and neither case is logged.
  • The client churns down to 0 peers and sync stops. It only recovers once the set is empty and the queue has drained, when 3 peers connect at once with normal lag. A few minutes later the cycle repeats.
  • In the teammate's run, one peer held ~36 MB / ~750 requests in flight on a link doing 0.1-0.3 MB/s, which is minutes of queue. Every new peer was kicked with 0 bytes received, and sync stalled for ~5 min (see fix(dash-spv): ByteLimiter cap runs away on slow peers on refactor/network-mod, starving header sync #1220 for the cap growth).

Activity

  1. xdustinface commented on Oct 28, 2026

    @xdustinface
    Collaborator

    The same collapse happens on a healthy client link, and the code path that empties the set is the timeout monitor itself. At 8dde9d0c, neither culprit path in dash-spv/src/network/manager.rs:1030-1066 (frozen byte counter or broker.expire) keeps a minimum, and peers.retain at manager.rs:1072-1083 drops every culprit of the tick, the last peer included, then bans each for 10 minutes (bans.rs:9, configured peers exempt). The "never sit at zero peers" rule (manager.rs:919-937) only applies when accepting peers, so it only helps after the supervisor wakes.

    Testnet evidence. 12 interleaved full syncs of 39eef40d against dev 0dcdd823 (same network code as dev now):

    • The refactor dropped to zero peers 8 times in 6 of 12 runs. Dev never did in 27 runs.
    • 7 episodes were a single tick kicking every peer, for example kicked 3 peer(s) {85.209.243.7, 68.67.122.34, 68.67.122.67}, retried 864, then PeersUpdated(0 peers) 1ms later. One was a cascade over three ticks (re-sent 41, 159, 187).
    • In every episode all kicked peers had stopped sending 10 to 18s before the kick. The client then sat at zero for 1 to 11s, and the replacements delivered within about 2s of connecting, so the peers were healthy.
    • 81 of the 94 testnet seeds are in 68.67.122.0/24, so one hiccup there looks like N independent stalls.
    • requeue_from wakes the router before the culprits are removed: right after one kick the router logged 75 sends with peers=3, the peers being closed.
    • Refactor runs with a drop had a median total of 450s, runs without one 318s (dev 319s).

    Suggested fix. Never kick the last peer, treat a tick where half or more of the connected peers stall as a shared stall (kick none, or only the worst), and remove culprits before re-routing their work. The long holds from ignored requests are tracked separately in #1230.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions