runtime-rs: health check can exit the shim during sandbox teardown, losing the Delete reply and leaking the TAP, shared dir and cgroup

Author: fivetimeCreated Sep 24, 2026Updated Sep 24, 2026

Description of problem

virt_container::health_check calls process::exit(1) when an agent check fails and no stop signal is pending (with the default keep_abnormal = false). Sandbox::stop() kills the VM first. The monitor is stopped only at the end of shutdown(), after cleanup(), so there is a window between VM stop and monitor stop.

If the 30 s check is due or in flight in that window, it fails against the dead VM and the shim exits in the middle of teardown. Two things follow:

  • the pending Shutdown/Delete reply is lost, so containerd reports ttrpc: closed to the caller;
  • cleanup() never runs, so the sandbox's persistent tap0_kata, /run/kata-containers/shared/sandboxes/<id> and its sandbox cgroup are left behind.

Expected result

Stopping a sandbox never looks like an agent failure. The shim finishes its cleanup and replies.

Actual result

Observed with runtime-rs 4.1.0 and QEMU. The code path is unchanged in 4.2.0 and on main.

Shim log around a container Delete:

begin stop sandbox
QemuInner::stop_vm(): kill()'ing qemu
oom watcher cancelled, sandbox is stopping
Failed to terminate pending RPC: the request has returned
failed to do nova-<id> agent health check: check health
failed to receive stop monitor signal

The shim process then exits. In a normal teardown those lines are followed by "sandbox stopped", QemuInner::cleanup() and "resource clean up" instead. containerd logs "shim disconnected" and "cleaning up dead shim", and the Delete caller gets ttrpc: closed. After this, the netns still holds the persistent tap0_kata, and the shared sandbox directory and the cgroup remain.

The window is roughly the duration of stop plus cleanup (about 100–150 ms), against a 30 s check interval, so it hits a small fraction of deletes.

Further information

A second issue in the same code: HealthCheck::stop() sends on a one-slot mpsc channel. If stop() is called again after the loop has already exited and consumed or dropped the signal, the second send blocks forever. Moving the stop earlier, into Sandbox::stop(), makes repeated calls normal: concurrent sandbox stops, and again from shutdown().

A fix will follow in a PR.

Source: kata-containers/kata-containers