← Back to Pull requests

netsync: clear ibdMode when the sync peer is dropped #2690

Open
unknown opened this pull request with 252 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 18, 2026 20:54 UTC
Author

In this PR, we fix a state leak in the sync manager that could leave a node permanently stuck behind the chain tip while connected to healthy peers.

Problem

ibdMode is set when startSync picks a sync peer, but it was only cleared when the final block of a download arrived. When the sync peer stalled or disconnected, updateSyncPeer set syncPeer to nil and called startSync. If no remaining peer advertised a height above ours (or the chain was already current), startSync returned without selecting a peer, and without touching ibdMode.

That left ibdMode set with no sync peer, which is a dead end:

  • handleInvMsg skips every announcement while ibdMode is set, so no new block is ever requested.

  • Peer heights never advance, so fetchHigherPeers stays empty.

  • With no peer connect or disconnect events, nothing calls startSync again.
  • A node in this state sits idle until it happens to connect to a new peer. I hit this on an outbound-only node (--nolisten, 8 peers): a goroutine dump showed blockHandler parked in its select, every peer sitting in a normal read, and no peer churn for ~16 hours, while the node was well behind the tip.

    Fix

    Clear ibdMode where syncPeer is cleared, so ibdMode can only be on while a sync peer is driving the download (ibdMode implies syncPeer != nil). startSync sets it again when it selects a replacement. Once cleared, announcements are processed again and a lagging node catches up through the usual orphan/getblocks path.

    TestIBDModeClearedWithoutSyncPeer covers both ways the sync peer goes away (stall sampler, disconnect), and fails without the change.

    Not covered

    A sync peer that keeps replying to getheaders with headers we already have resets lastProgressTime on every reply (handleHeadersMsg), so the stall sampler never fires even though our best header isn't advancing. That is a separate, pre-existing way to get a similar frozen state. It needs an unusual peer or fork, so I've left it for a follow-up.

    Diff: 252 lines (+189 / -63) across 3 files Reviewer: allocz Review duration: 19004m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 252 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.331
    Real PR Conversation Timeline
    1 comments
    "Review active on #2690"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39% (MEDIUM) · Higher = larger blast radius
    39%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.8% · Safe to merge
    20.8%
    Repository