Skip to content

microvm-worker: after the orphan sweep kills a VM, the startup probe can collide with it #797

Closed

Description

@webchang

Problem

At start, microvm-worker sweeps VM cgroups left under its slice (vmpool.SweepOrphans), then runs
pool.Probe, which restores vm-1. sweepOneCgroup kills each pid and then waits for the cgroup to
empty, but waitForCgroupEmpty gives up after 200 ms without saying so, and the sweep then counts the
cgroup as swept.

Observed on a KVM host, starting a worker whose slice held one leaked VM:

  1. "orphan sweep: swept 1", then at once "startup probe: could not restore a VM: firecracker: restore
    vm-1: a live VMM already holds this VM id's API socket at …/vm-1", and exit 1;
  2. after systemd's restart: "swept 0", then "API socket never appeared: timed out after 5s", and exit
    1, leaving a VM of its own behind;
  3. after a second restart: "swept 1", then the snapshot verified and pinned, and the worker attached.

So recovery relied on Restart=on-failure, cost two failed starts, and a failed probe itself leaked a
VM.

Proposal

  • sweepOneCgroup waits for the killed processes to exit for longer (bounded, a few seconds), and
    reports a cgroup that did not empty as not swept, logging it, instead of counting it.
  • Before pool.Probe, the worker waits (bounded) for the swept VM ids' API sockets to have no
    listener, the same check the launcher's collision test makes.
  • A failed probe tears down the VM it started before the worker exits.

What the PR will contain

remote-worker/internal/vmpool/cgroup.go (the wait and the report), remote-worker/cmd/microvm-worker
(the wait before the probe; the probe's teardown on failure), with tests for each.

Depends on

Nothing. Related: the worker-stop VM leak (separate issue), which is what leaves the orphan.

How to verify

go test ./remote-worker/internal/vmpool/... ./remote-worker/cmd/microvm-worker/...; on a KVM host,
start a worker whose slice holds a leaked VM: one start sweeps it and attaches.

Limits / out of scope

  • The waits are bounded; a VMM that does not exit within them still fails the start, now with a line
    saying which.

Assisted-By: Claude Code

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions