<!-- XE-13353 · Report bug · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13353>. The page is the record; this is the same page for reading.*

XE-13353 · Bounty

# Report bug

Closed · duplicate
—
[xe#498](https://github.com/xeprotocol/xe/issues/498)
filed 2026-11-12 03:49 UTC
by Gib230223

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:38 UTC

Told
:   2026-11-20 00:34 UTC

### Patches

- [xe#520](https://github.com/xeprotocol/xe/pull/520) open by arturbarszcz78
  fix(node): teardown orphaned VMs whose lease record is missing from store (fixes #498)

### History

- [554015](https://bounty.xe.network/log/554015) 2026-11-20 00:34 UTC reply.mirrored
- [553988](https://bounty.xe.network/log/553988) 2026-11-20 00:34 UTC github.state\_pushed
- [553940](https://bounty.xe.network/log/553940) 2026-11-20 00:34 UTC github.labels
- [552449](https://bounty.xe.network/log/552449) 2026-11-20 00:33 UTC proposal.adopted
- [552448](https://bounty.xe.network/log/552448) 2026-11-20 00:33 UTC reply.sent
- [552447](https://bounty.xe.network/log/552447) 2026-11-20 00:33 UTC ticket.status new → closed
- [551837](https://bounty.xe.network/log/551837) 2026-11-20 00:33 UTC proposal.adopted
- [551836](https://bounty.xe.network/log/551836) 2026-11-20 00:33 UTC ticket.facts area
- [551835](https://bounty.xe.network/log/551835) 2026-11-20 00:33 UTC proposal.adopted
- [551834](https://bounty.xe.network/log/551834) 2026-11-20 00:33 UTC ticket.facts
- [551833](https://bounty.xe.network/log/551833) 2026-11-20 00:33 UTC proposal.adopted
- [551832](https://bounty.xe.network/log/551832) 2026-11-20 00:33 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-13353) · [JSON](https://bounty.xe.network/v1/tickets/XE-13353) · [markdown](https://bounty.xe.network/XE-13353.md)

### Report

# XE Bounty — Laporan siap file (temuan pass 4 #3)

File issue baru di: https://github.com/xeprotocol/xe/issues/new
Paste judul \+ isi di bawah. Akun GitHub: Gib230223.

---

## Judul

\[Low\] `cleanupOrphanedVMs` skips exactly the VMs it is named for: lease record missing → VM never torn down

## Isi

## Summary

`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.

## Evidence

```
// node/node.go:1773-1791 — cleanupOrphanedVMs, runs every 10 s from settleLoop (:1757-1768):
for _, info := range n.VMManager.List() {
    lease, err := ls.GetLease(info.LeaseHash)
    if err != nil || lease == nil {
        continue            // <-- the orphan case is SKIPPED
    }
    if lease.State.Terminal() {
        log.Printf("Cleaning up orphaned VM for terminal lease %s", shortHash(info.LeaseHash))
        if err := n.VMManager.Teardown(info.LeaseHash); err != nil { ... }
    }
}

// store/badger_store.go:1572 + store/mem_store.go:710 — GetLease returns (nil, nil) for a missing row:
func (s *BadgerStore) GetLease(leaseHash string) (*core.Lease, error) {
    ...
    if err == badger.ErrKeyNotFound {
        return nil, nil
    }
    ...
}
func (m *MemStore) GetLease(leaseHash string) (*core.Lease, error) {
    ...
    l, ok := m.leases[leaseHash]
    if !ok {
        return nil, nil
    }
    ...
}
```

The `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.

## Impact (Low)

Reachability 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`).

## Reproduction (PoC)

`TestPoc4CleanupOrphanedVMs` (package `node`, `vm.NewMockManager()` \+ `MemStore`):

```
BUG: VM with NO lease record in the store survives cleanupOrphanedVMs (still 1 VM)
Cleaning up orphaned VM for terminal lease cccccccccccc...
CONTROL OK: VM whose lease is present-but-terminal IS torn down; only the missing-lease VM leaks
```

## Novelty note

No 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.

Repo: github.com/xeprotocol/xe, HEAD 89a542e, testnet-0005.

### Thread

**Joseph Denne**team2026-11-20 00:34 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-13353 and says what differs; it is read like any other.
