Bounty
XE-13225 · Bounty

node: uncoordinated n.wg.Add(1) and callback goroutines race with Stop() WaitGroup.Wait/store.Close and conflict/phantom pulls bypass pullSem

Closed · duplicate — xe#348 filed 2026-11-11 04:57 UTC by Khanhtnq

Report

Summary

node.Node mixes untracked background sweepers and store-touching callbacks with unguarded dynamic n.wg.Add(1) calls across asynchronous paths, while leaving conflict block/vote pull goroutines outside n.pullSem:

  1. Concurrent WaitGroup.Add vs Wait panic and post-Close store access during Stop():

    • node.New (node/node.go:275-292) launches quorumMgr.StartStaleConflictSweep(ctx.Done()) and the 15s voteMgr.SweepFrontiers() ticker outside n.wg, wires ledger.SetConflictCallback(voteMgr.OnConflict) and ledger.SetBlockAddedCallback(voteMgr.OnBlockAdded) (node/node.go:278-279, invoked via go cb(...) inside core/ledger.go) plus xenet.SetupCertSync(..., n.ingestCertificate) (node/node.go:581) without n.wg tracking, and mutates n.QuorumMgr.PhantomPullFn and n.QuorumMgr.VotePullFn ~300 lines after starting the sweepers (node/node.go:584, 587) without synchronization.
    • Node.Stop() (node/node.go:1301-1309) cancels n.ctx, calls n.wg.Wait(), and closes n.store. Meanwhile, untracked sweepers/callbacks, go qm.OnFinalized() (core/quorum.go:408-410 -> voteMgr.SweepFrontiers -> pullFrontierVotes), sc.SetOnBlock (node/node.go:506), handleIncoming (node/node.go:722), and leaseWatchTick (node/node.go:1692) can invoke n.wg.Add(1) concurrently with n.wg.Wait() (triggering Go's sync: WaitGroup misuse: Add called concurrently with Wait panic) or continue reading/writing n.store after n.store.Close().
  2. Unbounded conflict/phantom pull goroutines and missing post-pull Retally:

    • pullFrontierVotes (node/node.go:926-949) bounds concurrency via n.pullSem (maxInFlightVotePulls = 32), whereas pullPhantomBlocks (node/node.go:887-907) and pullConflictVotes (node/node.go:909-924) spawn a new goroutine on every call without acquiring n.pullSem. Each 15s stale-conflict sweep (core/quorum.go:523-589) iterates GetAllConflicts() and can spawn unbounded concurrent P2P stream goroutines across open conflicts.
    • When pullPhantomBlocks retrieves missing candidate bodies after quorum votes have already been recorded, Ledger.AddBlock stages the candidate body in ConflictStore without re-running QuorumMgr.Retally(account, previous), leaving resolvable conflicts stalled until the next external vote event.

Locations (origin/master @ 89a542ea)

  • node/node.go:275-292, 506, 551-640, 672, 722, 887-949, 1301-1309, 1692
  • core/quorum.go:408-428, 523-589

Reproduction / Impact

  • Calling Node.Stop() while QuorumMgr callbacks (PhantomPullFn, VotePullFn, OnFinalized), Ledger conflict/block callbacks, or leaseWatchTick fire concurrently triggers sync.WaitGroup misuse panics or accesses n.store after n.store.Close().
  • Calling pullPhantomBlocks and pullConflictVotes across >32 open conflicts spawns unbounded P2P stream goroutines instead of respecting maxInFlightVotePulls = 32.

Thread

Joseph Denneteam2026-11-20 00:05 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-13225 and says what differs; it is read like any other.