{"id":"XE-0920","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":13,"title":"Queued VM provision blocks shutdown and further SIGINT is swallowed","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-06T16:55:41.648739+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":null,"told_at":"2026-11-08T20:18:46.940927+00:00","status_changed_at":"2026-11-08T20:18:19.818806+00:00","url":"https://bounty.xe.network/XE-0920","body":"## Summary\r\nNode shutdown is supposed to cancel in-flight work and exit, with a second SIGINT restoring default terminate. cmd/xe/main.go:1559-1563 reads sigCh once (buffer 1, Notify never Stopped); defer n.Stop at :1419 runs cancel then wg.Wait then store.Close (node.go:1301-1308). Gossip auto-accept spawn at node.go:721-726 does n.wg.Add(1) around autoAcceptLease then Provision; LimaManager.Provision at vm/lima_manager.go:94-99 holds m.mu across create/start/SSH wait, and runLimactlWithTimeout at :296 uses time.After at :319, not n.ctx (call sites at :118-131), so cancel() does not unblock it. An operator hitting Ctrl-C during auto-accept on a provider node takes this path. GitHub #44 is sync OOM and desk XE-0041 / xe#60 is SIGTERM during sync hanging shutdown; this is lima time.After plus Stop wg.Wait plus Notify buffer-1 on the provider path.\r\n\r\n## Affected components\r\ncmd/xe/main.go:1559-1563 signal.Notify buffer-1 single read; cmd/xe/main.go:1419 defer Stop; node/node.go:721-726 autoAcceptLease wg.Add around Provision; node/node.go:1301-1308 Node.Stop (cancel, wg.Wait, store.Close); vm/lima_manager.go:94-99 Provision m.mu; vm/lima_manager.go:118-131 Provision call sites; vm/lima_manager.go:296 runLimactlWithTimeout; vm/lima_manager.go:319 time.After (ignores n.ctx) at xe 02e9641b0ac64437f57e09d63301f88cce61a802.\r\n\r\n## Impact\r\nAn operator hitting Ctrl-C during auto-accept waits on lima. By source read (not shown in the run): further SIGINT/SIGTERM do not restore default terminate, and the process is stuck until lima's own timeout or an external SIGKILL that skips a clean store.Close. Victim is a provider (--provide); default capacity bounds in-flight count to about one lima cycle, not hours.\r\n\r\n## PoC\r\n\r\n```go\r\npackage node\r\n\r\nimport (\r\n\t\"context\"\r\n\t\"fmt\"\r\n\t\"sync\"\r\n\t\"testing\"\r\n\t\"time\"\r\n\r\n\t\"github.com/libp2p/go-libp2p/p2p/net/mock\"\r\n\r\n\t\"github.com/xeprotocol/xe/core\"\r\n\t\"github.com/xeprotocol/xe/store\"\r\n)\r\n\r\n// TestPoC_Q2Stop: Node.Stop waits on n.wg after cancel(); a provision-like\r\n// goroutine holding wg (and a mutex) is not unblocked by cancel().\r\n//\r\n// DISCLOSE: the goroutine is a stand-in for autoAcceptLease -> provisionVM\r\n// -> LimaManager.Provision. Production runLimactlWithTimeout waits on\r\n// time.After, not n.ctx (proven separately by TestPoC_Q2Lima). Here we\r\n// sleep after ctx.Done() to show Stop cannot proceed until that work ends.\r\nfunc TestPoC_Q2Stop(t *testing.T) {\r\n\tfmt.Println(\"PROVENANCE: xe=02e9641b0ac64437f57e09d63301f88cce61a802 file=poc/round4/overlay/q2_shutdown_test.go\")\r\n\tcore.SetNetworkID(\"\")\r\n\tkp, err := core.GenerateKeyPair()\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"keygen: %v\", err)\r\n\t}\r\n\tmn := mocknet.New()\r\n\th, err := mn.GenPeer()\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"peer: %v\", err)\r\n\t}\r\n\tms := store.NewMemStore()\r\n\tl := core.NewLedger(ms, core.LedgerConfig{Difficulty: 0, TimestampWindow: 0})\r\n\tctx, cancel := context.WithCancel(context.Background())\r\n\tn := &Node{\r\n\t\tKeyPair:  kp,\r\n\t\tHost:     h,\r\n\t\tLedger:   l,\r\n\t\tstore:    ms,\r\n\t\tVoteMgr:  core.NewVoteManager(ms, kp, l),\r\n\t\tctx:      ctx,\r\n\t\tcancel:   cancel,\r\n\t\tsyncWait: func() {},\r\n\t}\r\n\r\n\tvar mu sync.Mutex\r\n\tvar muHeld time.Duration\r\n\tn.wg.Add(1)\r\n\tgo func() {\r\n\t\tdefer n.wg.Done()\r\n\t\tmu.Lock()\r\n\t\tselect {\r\n\t\tcase <-n.ctx.Done():\r\n\t\t\tt0 := time.Now()\r\n\t\t\ttime.Sleep(1500 * time.Millisecond)\r\n\t\t\tmuHeld = time.Since(t0)\r\n\t\tcase <-time.After(5 * time.Second):\r\n\t\t}\r\n\t\tmu.Unlock()\r\n\t}()\r\n\r\n\tdone := make(chan struct{})\r\n\tt0 := time.Now()\r\n\tgo func() {\r\n\t\tn.Stop()\r\n\t\tclose(done)\r\n\t}()\r\n\r\n\tblocked := false\r\n\tselect {\r\n\tcase <-done:\r\n\t\tfmt.Printf(\"KILL: Stop returned in %s while provision still held wg\\n\", time.Since(t0))\r\n\tcase <-time.After(800 * time.Millisecond):\r\n\t\tblocked = true\r\n\t\tfmt.Printf(\"Stop still blocked after 800ms (cancel already called, wg held)\\n\")\r\n\t}\r\n\r\n\tselect {\r\n\tcase <-done:\r\n\tcase <-time.After(3 * time.Second):\r\n\t\tt.Fatalf(\"Stop did not return after provision released\")\r\n\t}\r\n\tstopDur := time.Since(t0)\r\n\tfmt.Printf(\"Stop returned after %s muHeldAfterCancel=%s blocked=%v ctx.Err=%v\\n\", stopDur, muHeld, blocked, ctx.Err())\r\n\tif blocked && stopDur >= 800*time.Millisecond && ctx.Err() != nil {\r\n\t\tfmt.Println(\"PASS: Node.Stop blocked on wg.Wait past a bounded timeout while a provision-like goroutine ignored cancel()\")\r\n\t\tfmt.Println(\"VERDICT=CONFIRMED\")\r\n\t\treturn\r\n\t}\r\n\tfmt.Println(\"KILL: Stop did not block on wg\")\r\n\tfmt.Println(\"VERDICT=KILLED\")\r\n\tt.Fatalf(\"Stop did not block blocked=%v stopDur=%s\", blocked, stopDur)\r\n}\r\n```\r\n\r\n```\r\nPASS: Node.Stop blocked on wg.Wait past a bounded timeout while a provision-like goroutine ignored cancel()\r\n```\r\n\r\n## Suggested fix\r\nHonor n.ctx in lima timeouts, Stop() the signal Notify, and do not hold n.wg across Provision. Drain a second SIGINT so default terminate is restored.","patch_refs":[],"thread":[{"id":1100,"source":"desk","source_ref":"reply:649","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the behaviour you describe from the code and it is being handled alongside related shutdown work; we will update https://bounty.xe.network/XE-0920 when a fix lands.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}