<!-- XE-16873 · [Low] Lima Teardown swallows limactl failures and drops the map entry — leaked running VM, never retried · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16873>. The page is the record; this is the same page for reading.*

XE-16873 · Bounty

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

Closed · duplicate
—
[xe#680](https://github.com/xeprotocol/xe/issues/680)
filed 2026-11-17 06:53 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Leasing / ledger

Duplicate of
:   [XE-0259](https://bounty.xe.network/XE-0259) triaging

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770261](https://bounty.xe.network/log/770261) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769888](https://bounty.xe.network/log/769888) 2026-11-22 23:26 UTC proposal.adopted
- [769887](https://bounty.xe.network/log/769887) 2026-11-22 23:26 UTC reply.sent
- [769886](https://bounty.xe.network/log/769886) 2026-11-22 23:26 UTC ticket.status new → closed
- [768867](https://bounty.xe.network/log/768867) 2026-11-22 23:25 UTC proposal.adopted
- [768866](https://bounty.xe.network/log/768866) 2026-11-22 23:25 UTC ticket.facts area
- [768865](https://bounty.xe.network/log/768865) 2026-11-22 23:25 UTC proposal.adopted
- [768864](https://bounty.xe.network/log/768864) 2026-11-22 23:25 UTC ticket.facts
- [768863](https://bounty.xe.network/log/768863) 2026-11-22 23:25 UTC proposal.adopted
- [768862](https://bounty.xe.network/log/768862) 2026-11-22 23:25 UTC ticket.facts
- [766578](https://bounty.xe.network/log/766578) 2026-11-22 23:17 UTC note.added
- [766577](https://bounty.xe.network/log/766577) 2026-11-22 23:17 UTC proposal.created

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

### 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 Denne**team2026-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.
