{"id":"XE-13353","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"498","source_url":"https://github.com/xeprotocol/xe/issues/498","reporter_id":1981,"title":"Report bug","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:10.417231+00:00","updated_at":"2026-11-20T00:38:15.375881+00:00","source_created_at":"2026-11-12T03:49:43+00:00","told_at":"2026-11-20T00:34:50+00:00","status_changed_at":"2026-11-20T00:33:18.714637+00:00","url":"https://bounty.xe.network/XE-13353","body":"# XE Bounty — Laporan siap file (temuan pass 4 #3)\n\nFile issue baru di: https://github.com/xeprotocol/xe/issues/new\nPaste judul + isi di bawah. Akun GitHub: Gib230223.\n\n---\n\n## Judul\n\n[Low] `cleanupOrphanedVMs` skips exactly the VMs it is named for: lease record missing → VM never torn down\n\n## Isi\n\n## Summary\n\n`cleanupOrphanedVMs` (runs every 10 s from `settleLoop`) is the node's sweeper for orphaned VMs. But when a VM's lease row is missing from the store, it does `continue` — skipping the VM on every sweep forever — while a VM whose lease is present-but-terminal IS reaped. The function reaps the non-orphans and keeps the orphans. `GetLease` returns `(nil, nil)` for a missing lease in both stores, so a missing lease with a nil error is a definitive \"no such lease\", and nothing else ever reaps it.\n\n## Evidence\n\n```go\n// node/node.go:1773-1791 — cleanupOrphanedVMs, runs every 10 s from settleLoop (:1757-1768):\nfor _, info := range n.VMManager.List() {\n    lease, err := ls.GetLease(info.LeaseHash)\n    if err != nil || lease == nil {\n        continue            // <-- the orphan case is SKIPPED\n    }\n    if lease.State.Terminal() {\n        log.Printf(\"Cleaning up orphaned VM for terminal lease %s\", shortHash(info.LeaseHash))\n        if err := n.VMManager.Teardown(info.LeaseHash); err != nil { ... }\n    }\n}\n\n// store/badger_store.go:1572 + store/mem_store.go:710 — GetLease returns (nil, nil) for a missing row:\nfunc (s *BadgerStore) GetLease(leaseHash string) (*core.Lease, error) {\n    ...\n    if err == badger.ErrKeyNotFound {\n        return nil, nil\n    }\n    ...\n}\nfunc (m *MemStore) GetLease(leaseHash string) (*core.Lease, error) {\n    ...\n    l, ok := m.leases[leaseHash]\n    if !ok {\n        return nil, nil\n    }\n    ...\n}\n```\n\nThe `err != nil` half of the condition is defensible (transient DB error → retry next tick); the `lease == nil` half is not — a nil lease with a nil error is a definitive \"no such lease\". The restart-time `cleanOrphans` in QEMU/Lima only kills *processes/instances*, and the in-memory VM map is rebuilt from scratch on restart, so a lease-less VM is invisible to every other path too.\n\n## Impact (Low)\n\nReachability of a missing lease row is narrow in normal operation (leases are never deleted by node code; the realistic triggers are operator store resets, store corruption, or a lease that was accepted on a chain the node later replays without). Impact is a leaked live VM burning host vCPU/RAM/disk (and, for QEMU, holding the provider's sole VFIO GPU) with no manager-side record and no retry. Fix: treat `lease == nil && err == nil` as teardown-eligible (keep skipping on `err != nil`).\n\n## Reproduction (PoC)\n\n`TestPoc4CleanupOrphanedVMs` (package `node`, `vm.NewMockManager()` + `MemStore`):\n\n```\nBUG: VM with NO lease record in the store survives cleanupOrphanedVMs (still 1 VM)\nCleaning up orphaned VM for terminal lease cccccccccccc...\nCONTROL OK: VM whose lease is present-but-terminal IS torn down; only the missing-lease VM leaks\n```\n\n## Novelty note\n\nNo ticket covers the missing-lease skip. Board greps for `cleanupOrphan|orphan`, `finishSettle|settle.*teardown` return only: XE-7701 (Minor) — `cleanOrphans` kills orphan QEMU processes but never removes workDirs (different function, different leak: disk vs live VM, different fix); XE-6410 (High) — `Teardown` reports success while the guest still runs and then forgets the VM (different direction: that is the manager *forgetting a live VM it tried to tear down*; this is the node sweeper *never attempting* teardown for a VM with no lease row); XE-6742 / XE-5332 (lease-open swap orphans the provider's accept/stake — ledger-level orphaning, not VM reaping). GitHub `search_issues` for \"cleanupOrphanedVMs orphaned VM\" returns 1 hit: #191 (provider restart destroys VMs backing live Accepted leases — the *opposite* direction: reaping too aggressively on restart, not never reaping). Checked the live bounty board (High+Medium and Minor views) and the GitHub repo issues, 2026-11-12.\n\nRepo: github.com/xeprotocol/xe, HEAD 89a542e, testnet-0005.\n","patch_refs":[{"id":566,"repo":"xeprotocol/xe","kind":"pr","ref":"520","title":"fix(node): teardown orphaned VMs whose lease record is missing from store (fixes #498)","url":"https://github.com/xeprotocol/xe/pull/520","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-14T20:42:20.195805+00:00"}],"thread":[{"id":13216,"source":"github","source_ref":"7026486815","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-13353 and says what differs; it is read like any other.","created_at":"2026-11-20T00:34:50+00:00"}]}