Bounty
XE-16873 · Bounty

[Low] Lima Teardown swallows limactl failures and drops the map entry — leaked running VM, never retried

Closed · duplicate — xe#680 filed 2026-11-17 06:53 UTC by kecedanzz77-bit

Report

Summary

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.

Root Cause

vm/lima_manager.go:164-180:

_, _ = m.runLimactl("stop", v.name)
_, _ = m.runLimactl("delete", "--force", v.name)
_ = os.Remove(filepath.Join(m.templateDir, v.name+".yaml"))
delete(m.vms, leaseHash)
log.Printf("Lima VM %s torn down", v.name)
return nil

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

Impact

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

Verification

Executed in-package test with a fake limactl that fails stop/delete:

Teardown with failing limactl stop/delete: err=<nil>
VM still in manager map after failed teardown: false
List() after failed teardown: 0 VMs (cleanupOrphanedVMs iterates List, so it can never retry)

Note on related reports

Distinct 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).

Suggested fix

Return an error (or keep the map entry) when stop/delete fails, so cleanupOrphanedVMs retries the teardown on its next pass.

Thread

Joseph Denneteam2026-11-22 23:26 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0259, 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-16873 and says what differs; it is read like any other.