{"id":"XE-16873","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"680","source_url":"https://github.com/xeprotocol/xe/issues/680","reporter_id":2920,"title":"[Low] Lima Teardown swallows limactl failures and drops the map entry — leaked running VM, never retried","area":"leasing-ledger","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0259","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:53:56.680387+00:00","updated_at":"2026-11-22T23:26:13.061884+00:00","source_created_at":"2026-11-17T06:53:45+00:00","told_at":"2026-11-22T23:26:13.081001+00:00","status_changed_at":"2026-11-22T23:26:13.067914+00:00","url":"https://bounty.xe.network/XE-16873","body":"## Summary\n\n`LimaManager.Teardown` discards `limactl stop`/`delete` errors, deletes the VM from its in-memory map unconditionally, and returns `nil` — so a failed teardown leaves a running VM that is invisible to the orphan sweeper and never retried. The provider keeps paying host resources for a dead lease until the node is restarted.\n\n## Root Cause\n\n`vm/lima_manager.go:164-180`:\n\n```go\n_, _ = m.runLimactl(\"stop\", v.name)\n_, _ = m.runLimactl(\"delete\", \"--force\", v.name)\n_ = os.Remove(filepath.Join(m.templateDir, v.name+\".yaml\"))\ndelete(m.vms, leaseHash)\nlog.Printf(\"Lima VM %s torn down\", v.name)\nreturn nil\n```\n\nBoth limactl errors are discarded (`:173-174`), the template YAML is deleted even on failure (`:175`), the map entry is removed (`:176`), and the function reports success (`:179`). `cleanupOrphanedVMs` iterates `List()` (`node/node.go:1814-1835`), so after one failed teardown the VM is invisible and never retried; only `cleanOrphans` at manager startup (`vm/lima_manager.go:85`, `:325`) reclaims it — i.e. only a node restart.\n\n## Impact\n\nProvider keeps paying host resources (CPU/RAM/disk + the SSH port) for a VM backing a dead lease, indefinitely until restart. Repeated teardown failures (e.g. a wedged limactl) leak one VM per failed lease.\n\n## Verification\n\nExecuted in-package test with a fake limactl that fails stop/delete:\n\n```\nTeardown with failing limactl stop/delete: err=<nil>\nVM still in manager map after failed teardown: false\nList() after failed teardown: 0 VMs (cleanupOrphanedVMs iterates List, so it can never retry)\n```\n\n## Note on related reports\n\nDistinct from #658 (QEMU workdir leak on *provision* failure), #498 (sweeper skips missing lease records), and #191 (provider restart destroys VMs — a startup-reap issue, different mechanism from a swallowed teardown error).\n\n## Suggested fix\n\nReturn an error (or keep the map entry) when stop/delete fails, so `cleanupOrphanedVMs` retries the teardown on its next pass.\n","patch_refs":[],"thread":[{"id":18815,"source":"desk","source_ref":"reply:16492","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0259, 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-16873 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:13.061884+00:00"}]}