runtime-rs: inotify close during ConfigMap teardown wedges tokio (pod stuck Terminating)

Author: pamanseauCreated Aug 15, 2026Updated Sep 23, 2026

Summary

FsWatcher in share_fs_volume.rs holds an inotify fd to copy kubelet ConfigMap / projected / secret / downward-api updates into the guest when virtio-fs is not used (or as the host-side watch for the copy path).

On the last volume reference, VolumeManager::release_volume aborts the monitor task. The task's Arc<Mutex<Inotify>> then drops on a tokio worker. Inotify::drop → close(2) → inotify_release → fsnotify_wait_marks_destroyed → flush_delayed_work.

When the watched path is a kubelet volume being unmounted in the same teardown, that flush can block uninterruptibly (D-state). Both tokio workers get stuck in the same close(2). The runtime-rs executor stops making progress:

  • no further kata logs
  • Shutdown never reaches stop_vm / start_kill
  • QEMU stays up and keeps VFIO devices
  • CRI sandbox stays Ready
  • the pod stays Terminating until runtime-request-timeout (often 2h)

This is not the large-guest QEMU reclaim hang (#13564 / #13597) and not the QMP blockdev-add duplicate-drive hang (#11649). QEMU is healthy (poll_schedule_timeout, 0 D-state threads). The shim is the one wedged.

Production evidence (Intel TDX + NVIDIA CC, ~1.2 TiB guest)

Pod delete at 09:34:34Z. Last shim lines: HAProxy container exit 0, agent remove_container EROFS (guest root is erofs), share-fs cleanup of ConfigMap eastwest-haproxy + projected SA, QMP DEVICE_DELETED for drive-9 succeeded. Then silence for 50+ minutes.

Shim threads:

tid 867691  Dl  flush_work
tid 867692  Dl  flush_work

Kernel stacks (both workers):

inotify_release
  fsnotify_destroy_group
    fsnotify_wait_marks_destroyed
      flush_delayed_work / __flush_work
        __x64_sys_close

CRI: containers gone, sandbox still Ready. QEMU still parented by the shim, holding 8 GPUs via VFIO.

Related but distinct: #10411 (inotify event order for ConfigMap updates). This issue is teardown close(2) blocking the executor.

Proposed fix

Do not run Inotify::drop / close(2) on a tokio worker.

Wrap the fd so Drop moves close(2) onto a dedicated OS thread (spawn-and-forget). A hung close may leak one OS thread; it must not pin the async runtime. Same idea as OS-thread QEMU reap on large-guest teardown.

Optional follow-up (not required to unblock Shutdown): inotify_rm_watch all watches before close; stop the monitor with a cancellation token instead of abort().

How to reproduce

  1. runtime-rs sandbox with at least one watchable volume (kubernetes.io~configmap or ~projected) and a second container (so volume cleanup runs on container delete, not only sandbox stop).
  2. kubectl delete pod (graceful; do not --force).
  3. If the kubelet unmounts the ConfigMap while the shim still holds watches, the shim tokio workers enter D-state in inotify_release and the pod stays Terminating with QEMU still running.

Source: kata-containers/kata-containers