{"id":"XE-13225","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"348","source_url":"https://github.com/xeprotocol/xe/issues/348","reporter_id":2,"title":"node: uncoordinated n.wg.Add(1) and callback goroutines race with Stop() WaitGroup.Wait/store.Close and conflict/phantom pulls bypass pullSem","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:00.786246+00:00","updated_at":"2026-11-20T00:07:02.198488+00:00","source_created_at":"2026-11-11T04:57:03+00:00","told_at":"2026-11-20T00:05:06+00:00","status_changed_at":"2026-11-20T00:04:39.303219+00:00","url":"https://bounty.xe.network/XE-13225","body":"### Summary\n\n`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`:\n\n1. **Concurrent `WaitGroup.Add` vs `Wait` panic and post-`Close` store access during `Stop()`**:\n   - `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.\n   - `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()`.\n\n2. **Unbounded conflict/phantom pull goroutines and missing post-pull `Retally`**:\n   - `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.\n   - 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.\n\n### Locations (`origin/master` @ `89a542ea`)\n\n- `node/node.go:275-292, 506, 551-640, 672, 722, 887-949, 1301-1309, 1692`\n- `core/quorum.go:408-428, 523-589`\n\n### Reproduction / Impact\n\n- 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()`.\n- Calling `pullPhantomBlocks` and `pullConflictVotes` across >32 open conflicts spawns unbounded P2P stream goroutines instead of respecting `maxInFlightVotePulls = 32`.","patch_refs":[{"id":540,"repo":"xeprotocol/xe","kind":"pr","ref":"349","title":"fix(node,core): gate shutdown goroutine spawns and bound conflict pull concurrency","url":"https://github.com/xeprotocol/xe/pull/349","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-14T20:42:19.648178+00:00"}],"thread":[{"id":12814,"source":"github","source_ref":"7025802918","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-13225 and says what differs; it is read like any other.","created_at":"2026-11-20T00:05:06+00:00"}]}