{"id":"XE-12837","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":827,"title":"Node.Stop() stalls ~80 s on an in-flight performance-certificate benchmark (RunBenchmark takes no ctx)","area":"node-api","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-13399","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T13:01:30.911017+00:00","updated_at":"2026-11-20T19:46:01.720844+00:00","source_created_at":null,"told_at":"2026-11-20T19:46:01.763844+00:00","status_changed_at":"2026-11-20T19:46:01.740012+00:00","url":"https://bounty.xe.network/XE-12837","body":"# [Minor] Node.Stop() stalls ~80 s on an in-flight performance-certificate benchmark (RunBenchmark takes no ctx)\n\n**Area:** node-api / node lifecycle\n**Repo pin:** `xeprotocol/xe` @ `89a542e` (HEAD, verified 2026-11-14)\n**Suggested tier:** Minor (CVSS 4.0 — local only, no remote trigger; a bounded shutdown delay, no crash, no leak, no state corruption, no funds)\n**Related public issue:** `xeprotocol/xe#561` (same ground, filed by another researcher; this report is an independent reproduction with our own Go test and our own measurements)\n\n## Summary\n\n`Node.Stop()` waits out a running performance-certificate benchmark whenever a certificate attempt is in flight: an operator who stops the node during a cert attempt waits **~80 s with no response** (no timeout, no interrupt). Measured at HEAD: benchmark wall **83.12 s**, Stop latency **78.18 s** (Stop issued 1 s into a live `maintainCertificate` attempt). The stall is bounded to one attempt — after it fails/completes, the loop re-checks ctx and returns — but the benchmark runs at node start (no cert yet) and at each renewal, so the window recurs on every cert cycle.\n\n## Root cause\n\nA ~65–85 s CPU-bound, non-cancellable unit of work sits inside a wg-tracked goroutine whose only ctx checks are between attempts:\n\n- `perf/benchmark.go:15,17` — `PoWPuzzles = 1024`, 19-bit puzzles; `:114` `RunBenchmark(seed, puzzles)` takes **no ctx** and solves the puzzles sequentially.\n- `node/perf.go:58` — `generatePerformanceCertificate` calls `perf.RunBenchmark(seed, perf.PoWPuzzles)`.\n- `node/perf.go:201` — `certGenerationLoop` checks ctx only **between** attempts (`if ctx.Err() != nil { return false }` before each `attempt()` call); nothing checks ctx mid-attempt.\n- `node/perf.go:158` — `maintainCertificate` runs the loop; `node/node.go:557` spawns it as a wg-tracked goroutine.\n- `node/node.go:1301-1308` — `Stop()` calls `n.cancel()` and then `n.wg.Wait()` at `:1303` with **no timeout**. The cancelled ctx cannot interrupt the benchmark, so `Stop()` waits for the puzzles to finish.\n\n## Reproduction (our own Go test, `node/zz_r56_m4_stopstall_b56_test.go`, NO -race)\n\nTwo parts, both against the real code at HEAD, 2026-11-14:\n\n- **(A) The blocking unit itself:** `perf.RunBenchmark(seed, perf.PoWPuzzles)` — wall **83.12 s** (result.Elapsed 83.118 s, score 0.0120). (Slower than the ~64–68 s seen on a quieter VM — same 1024-puzzle workload, same code path; run-to-run CPU variance on a shared VM.)\n- **(B) Stop latency:** a real node built by `New()`; `maintainCertificate` spawned exactly as production does (wg-tracked goroutine, `node/node.go:557` shape) with an attempt whose blocking unit is the real `RunBenchmark(1024)`; `Stop()` issued 1 s into the live attempt (gated on an atomic \"attempt started\" flag, so the timing is deterministic). **Stop latency: 78.18 s** — Stop waited out the remainder of the in-flight benchmark.\n\nThe test asserts the stall (Stop latency > 30 s) rather than an exact figure, since the wall time is CPU-dependent; the mechanism (no ctx in the benchmark, no timeout in `Stop()`) is what the numbers demonstrate. Total test time ~162 s, no `-race` (race-detector overhead on this CPU-bound code is ~10–15×, making a `-race` run infeasible).\n\n## Impact / worst case\n\n- An operator stopping the node during a cert attempt (SIGTERM during an upgrade or restart) sees an unresponsive shutdown for the remainder of the attempt (~65–85 s from the operator's point of view). The window recurs at node start and at each renewal, so an operator stopping the node has a realistic chance of hitting it.\n- **Bounded:** after the in-flight attempt fails/completes, the loop re-checks ctx and returns, so `Stop()` waits at most ONE attempt, not the whole retry chain. No remote trigger, no crash, no leak, no state corruption, no funds: a bounded shutdown delay. Hence Minor.\n\n## Duplicate check (re-verified at filing time, 2026-11-14 ~12:52–13:0x UTC)\n\n- Board search `q=RunBenchmark` → XE-4975, XE-11975 only. XE-4975 (new High — provider forges its benchmark score because `work_proof`/`cpu_hash` are never recomputed, `VerifyWork` has zero callers) is a **trust** defect about certificate verification, not shutdown latency; read in full. XE-11975 is a correction addendum to a cert price-multiplier ticket. Neither mentions `Stop()` or shutdown.\n- `q=maintainCertificate` → **0 hits**. `q=\"Node.Stop\"` → XE-0041, XE-0920 only. XE-0041 (accepted Medium — SIGTERM-during-sync hang, sync ctx from `Background()`) and XE-0920 (triaging Medium — queued VM provision blocks shutdown, Lima `time.After`) are different functions with different blocking work; both read in full.\n- No board ticket names a benchmark-induced `Stop()` stall. `q=aurorabelle788` → 1 hit, XE-12805 (our own earlier filing) — the #561 author has not filed on the board. No new public filings since XE-12805 (XE-12806–XE-12825 all 404); xe HEAD still `89a542e`, pull-refs still 186, max PR #556 — no fix PR.\n\n## Remediation suggestion\n\nMake the benchmark interruptible (pass a ctx into `RunBenchmark` / `solvePuzzle` and check it between puzzles), or bound the wait in `Stop()` (wait on the WaitGroup with a timeout, then proceed to close the host/store and let the benchmark goroutine finish in the background), or both. Checking ctx between puzzles keeps the per-puzzle work intact while capping the shutdown delay at one puzzle (~65 ms) instead of one attempt (~80 s).","patch_refs":[],"thread":[{"id":15464,"source":"desk","source_ref":"reply:13355","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-13399, 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-12837 and says what differs; it is read like any other.","created_at":"2026-11-20T19:46:01.720844+00:00"}]}