Repository navigation
Description
Problem
deploy/sbx/[email protected] runs each template worker in Slice=sbx-%i.slice with
KillMode=control-group. The worker's VMs are not in the service's own cgroup: jailer places each one
in a pool cgroup (pool-N) under the worker's slice, a sibling of the service's cgroup. So when
systemd stops the unit, control-group kills only the worker process's cgroup. The VMs depend on the
worker's own shutdown to be torn down.
Observed on a KVM host: a worker started, verified its snapshot, and began its standby pool fill. About
20 s later it was stopped (systemctl stop, from a host agent's wanted state). The unit went inactive,
but one /firecracker --id vm-1 (PPID 1) kept running in sbx.slice/sbx-<worker>.slice/pool-0,
holding its guest memory. Nothing reaped it until the next start of that worker ran its orphan sweep
(SweepOrphans).
A leaked VM keeps its memory (the snapshot's memory file is pinned and the guest's pages stay
resident) outside every budget the worker and the control plane count, until that worker is started
again, which may be never if the template is retired.
Proposal
Make a stop take the worker's VMs with it, whatever path the worker's own exit takes:
[email protected]gains anExecStopPost=that kills every VM cgroup under the worker's own
slice (cgroup.killon eachpool-*directory thatSweepOrphanswould sweep), and waits for them
to empty (bounded). It runs after the worker exits, on a clean stop, a crash or a timeout, so it
covers a stop that lands during a restore.- Optionally, the worker's SIGTERM path waits for in-flight restores before
pool.Close, so a clean
stop never needs the post step. The unit's post step stays as the guarantee.
What the PR will contain
deploy/sbx/[email protected](ExecStopPost=), a small helper if the unit line gets long, and
deploy/sbx/tests/install-host.test.sh(the installed unit carries it).- If the worker-side change is taken:
remote-worker/cmd/microvm-worker(the SIGTERM path) with a
test that a stop during a fill leaves no VM. deploy/sbx/RUNBOOK.md: how to find and reap a leaked VM by cgroup.
Depends on
Nothing. Related: the orphan-sweep wait (separate issue).
How to verify
On a KVM host: start a worker and stop it during its pool fill. After the stop, the worker's slice
holds no pool-* cgroup with processes, and no firecracker process remains for it.
Limits / out of scope
deploy/microvm's own P4 worker unit has the same shape; whether it needs the same step is for that
unit's owners.
Assisted-By: Claude Code
Activity
Merge upstream/main (d4babb8) into fix/795-worker-stop-reaps-vms
Merge upstream/main (634781a) into fix/795-worker-stop-reaps-vms
fix(sbx): end a stopped worker's VMs from the unit's ExecStopPost
docs(sbx): finding and reaping a VM a stopped worker left behind
feat(sbx): SBX_WORKER_AT_BOOT=0 installs a worker without enabling it…