AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 60 Bitcoin

discovery: fix endless loop in gossip syncer on context cancellation

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

85/100 · Strong
discovery: fix endless loop in gossip syncer on context cancellation

This commit fixes a critical bug where the channelGraphSyncer goroutine
would enter an endless loop when context cancellation or peer disconnect
errors occurred during the syncingChans or queryNewChannels states.

The root cause was that state handler functions (handleSyncingChans and
synchronizeChanIDs) did not return errors to the main goroutine loop.
When these functions encountered fatal errors like context cancellation,
they would log the error and return early without changing the syncer's
state. This caused the main loop to immediately re-enter the same state
handler, encounter the same error, and loop indefinitely while spamming
error logs.

The fix makes error handling explicit by having state handlers return
errors. The main channelGraphSyncer loop now checks these errors and
exits cleanly when fatal errors occur. We return any error (not just
context cancellation) because fatal errors can manifest in multiple
forms: context.Canceled, ErrGossipSyncerExiting from the rate limiter,
lnpeer.ErrPeerExiting from Brontide, or network errors like connection
closed. This approach matches the error handling pattern already used in
other goroutines like replyHandler.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a bug in LND's gossip syncer where a background goroutine could get stuck in an endless loop when a peer disconnected or its work was cancelled. Instead of exiting cleanly, the goroutine would repeatedly try the same step, flood error logs, and never stop. The fix makes the goroutine return errors to its main loop so it can shut down properly.

Recommended action

Apply the patch. Monitor for any remaining state handlers that swallow fatal errors without returning them. Consider adding a defensive guard in the main loop to prevent re-entry of the same state on repeated handler errors.

Security signals we found

01

Endless loop in a long-running goroutine leading to resource exhaustion and log spam

02

Failure to propagate fatal errors from state handlers to the main event loop

03

Context cancellation and peer disconnect not treated as terminal conditions

04

Pattern inconsistency with other goroutines like replyHandler that already returned errors

Risk score

Why this scored 60/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 10/15
Affected reach 12/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.