<!-- XE-13225 · node: uncoordinated n.wg.Add(1) and callback goroutines race with Stop() WaitGroup.Wait/store.Close and conflict/phantom pulls bypass pullSem · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13225>. The page is the record; this is the same page for reading.*

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](https://github.com/xeprotocol/xe/issues/348)
filed 2026-11-11 04:57 UTC
by Khanhtnq

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:07 UTC

Told
:   2026-11-20 00:05 UTC

### Patches

- [xe#349](https://github.com/xeprotocol/xe/pull/349) open by Khanhtnq
  fix(node,core): gate shutdown goroutine spawns and bound conflict pull concurrency

### History

- [543826](https://bounty.xe.network/log/543826) 2026-11-20 00:06 UTC github.state\_pushed
- [543825](https://bounty.xe.network/log/543825) 2026-11-20 00:06 UTC github.labels
- [543765](https://bounty.xe.network/log/543765) 2026-11-20 00:05 UTC reply.mirrored
- [543524](https://bounty.xe.network/log/543524) 2026-11-20 00:04 UTC proposal.adopted
- [543523](https://bounty.xe.network/log/543523) 2026-11-20 00:04 UTC reply.sent
- [543522](https://bounty.xe.network/log/543522) 2026-11-20 00:04 UTC ticket.status new → closed
- [542077](https://bounty.xe.network/log/542077) 2026-11-20 00:04 UTC proposal.adopted
- [542076](https://bounty.xe.network/log/542076) 2026-11-20 00:04 UTC ticket.facts area
- [542075](https://bounty.xe.network/log/542075) 2026-11-20 00:04 UTC proposal.adopted
- [542074](https://bounty.xe.network/log/542074) 2026-11-20 00:04 UTC ticket.facts
- [542073](https://bounty.xe.network/log/542073) 2026-11-20 00:04 UTC proposal.adopted
- [542072](https://bounty.xe.network/log/542072) 2026-11-20 00:04 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-13225) · [JSON](https://bounty.xe.network/v1/tickets/XE-13225) · [markdown](https://bounty.xe.network/XE-13225.md)

### 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 Denne**team2026-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.
