<!-- XE-16757 · [Medium] VM managers hold the global lock during multi-minute provisioning, blocking SSH dialing and teardown for all tenants · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16757>. The page is the record; this is the same page for reading.*

XE-16757 · Bounty

# \[Medium\] VM managers hold the global lock during multi-minute provisioning, blocking SSH dialing and teardown for all tenants

Closed · duplicate
—claimed Medium
[xe#656](https://github.com/xeprotocol/xe/issues/656)
filed 2026-11-17 05:46 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   Leasing / ledger

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

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770278](https://bounty.xe.network/log/770278) 2026-11-22 23:26 UTC reply.mirror\_failed
- [770078](https://bounty.xe.network/log/770078) 2026-11-22 23:26 UTC proposal.adopted
- [770077](https://bounty.xe.network/log/770077) 2026-11-22 23:26 UTC reply.sent
- [770076](https://bounty.xe.network/log/770076) 2026-11-22 23:26 UTC ticket.status new → closed
- [769286](https://bounty.xe.network/log/769286) 2026-11-22 23:26 UTC proposal.adopted
- [769285](https://bounty.xe.network/log/769285) 2026-11-22 23:26 UTC ticket.facts area
- [769284](https://bounty.xe.network/log/769284) 2026-11-22 23:26 UTC proposal.adopted
- [769283](https://bounty.xe.network/log/769283) 2026-11-22 23:26 UTC ticket.facts
- [769282](https://bounty.xe.network/log/769282) 2026-11-22 23:26 UTC proposal.adopted
- [769281](https://bounty.xe.network/log/769281) 2026-11-22 23:26 UTC ticket.facts
- [766151](https://bounty.xe.network/log/766151) 2026-11-22 23:17 UTC note.added
- [766146](https://bounty.xe.network/log/766146) 2026-11-22 23:17 UTC proposal.created

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

### Report

## Summary

`LimaManager.Provision` and `QEMUManager.Provision` hold the manager-wide write lock for their entire duration \-- up to \~9 min for Lima (2 min create \+ 5 min start \+ 2 min SSH wait) \-- while running blocking subprocess calls. During that window every other VM operation blocks: `DialSSH` (tunnel handler -\> SSH access for *all* tenants stalls), `Teardown` (settle/cancel cleanup stalls), `List`/`Get` (capacity checks, API `/vms` stall). Provisions serialize on the same lock, so chained leases sustain the blockage.

## Root Cause

- `vm/lima_manager.go:94-96`: `Provision` takes `m.mu.Lock()`, `defer m.mu.Unlock()` at the top, then runs `runLimactlWithTimeout(2min, "create")`, `runLimactlWithTimeout(5min, "start")`, `waitForSSHPort(name, 2min)`.
- `vm/qemu_manager.go:144-146`: same pattern.
- `vm/lima_manager.go:182-185` (`DialSSH` takes `RLock`), `:164-166` (`Teardown` takes `Lock`) \-- both block while a provision holds the write lock.

## Impact

- Remote, cheap trigger: `provisionVM` (`node/vm.go:74`) \<- `autoAcceptLease` \<- gossiped `BlockLease` \-- any user creating a lease to the provider triggers it. `MaxConcurrent` defaults to 0 \= "bounded only by resource capacity" (`cmd/xe/main.go:1311`), so with minimum-size leases (1 vCPU/512 MB/5 GB) an attacker can queue many provisions; escrow is refundable via cancel.
- All tenants' SSH access stalls (tunnel handler calls `DialSSH`), teardown stalls (settle/cancel cleanup), capacity checks stall.

## Verification (executed PoC)

Fake `limactl` that sleeps 30 s in `create`:

```
List() BLOCKED for >15s while a provision is in flight (lock held)
Get() BLOCKED for >10s while a provision is in flight (lock held)
provision finished, err: get ssh port: ssh port not ready after 2m0s
```

Audited at HEAD `8cc209d` (testnet-0006).

## Suggested fix

Hold the lock only for map mutations; do the long subprocess work outside it (e.g. reserve the lease hash, release the lock, provision, re-lock to register). Add a provisioning-state entry so concurrent `Provision` for the same lease still dedups.

### Thread

**Joseph Denne**team2026-11-22 23:26 UTCdesk

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