Skip to content

loadShims can hang forever at startup if a single leftover shim's Task.Delete never replies #13848

Open

Description

@Ayush-Rathor

Title

containerd hangs forever on startup and never self-recovers once a node accumulates leftover task/shim state — self-perpetuating crash loop

Environment

  • Affected: containerd 2.2.2 (prod) and 2.3.1 (staging) — identical symptom on both.
  • Kubernetes worker nodes, containerd as CRI, runtime v2.
  • Two runtimes registered: runc (containerd-shim-runc-v2) and gVisor (containerd-shim-runsc-v1 / runsc).
  • State dir on tmpfs (/run/containerd); root on disk (/var/lib/containerd).
  • Pods restart very frequently under gVisor (individual pods at 221 and 537+ restarts) → lots of leftover state accumulates.
  • No [timeouts] block configured (defaults in use).

Summary

containerd never finishes starting and never recovers on its own, no matter how many restarts. Once a node breaks, it stays broken until manual intervention, and that only holds until the next containerd restart (crash/OOM/upgrade/manual), when it can fall right back in. Our affected nodes had already failed 412, 457, and 636+ restarts identically before we investigated.

Steps to reproduce

A. Observed in prod/staging (verified real behavior, not a guess)

  1. Run containerd 2.2.2/2.3.1 as CRI with gVisor registered alongside runc, state dir on tmpfs.
  2. Run workloads that restart frequently under gVisor over time → leftover shims whose tasks already exited but haven't been cleaned up.
  3. Restart containerd for any reason (we couldn't identify the original trigger on any of the three nodes).
  4. containerd never finishes starting: no socket, ctr version hangs, systemd kills + restarts in an endless loop.

B. Minimal repro (we ran it ourselves; reproduced on the first attempt)
First naive attempt: start a runc container, kill its task directly, then kill -STOP the whole shim so it can't respond to anything → it recovered on its own in ~10s (containerd logged the shim as unreachable and moved on). So a totally unresponsive shim is not enough to reproduce this. That told us the real production shims must still answer most requests and only fail one specific kind.

Second attempt: put a small relay on the shim's connection that passes everything through unchanged except silently dropping only the one request that asks the shim to confirm/finalize its task is gone — never forwarded, never answered. Everything else (announce, "no running process left", etc.) passed and got answered normally.

Steps:

  1. Spare/non-prod node, containerd with runc as default.
  2. Start a container in its own namespace → running task + shim.
  3. Kill the task's main process directly (not via containerd) → task exits, shim left with nothing to manage.
  4. Route the shim's comms through the relay, dropping only the "confirm task is gone" request. (We first ran the relay fully transparent and confirmed it correctly identified that request type, so we knew we were targeting the right one.)
  5. Restart containerd.
  6. Result: hung exactly as above — stuck at activating for the full startup timeout, killed by systemd, restarted, stuck identically on the next attempt. Removing the relay → recovered on the following restart.
  7. Cleaned up container + relay; node returned to fully healthy.

Same failure mode: startup asks a leftover shim to confirm its task is gone; if that one request never gets answered — for any reason — startup hangs forever regardless of whether the shim is otherwise fine.

Expected behavior

containerd starts, creates its socket, and kubelet can manage pods within a normal window (a few seconds to low tens of seconds).

Actual behavior

Socket never created. systemctl status containerd shows Active: activating (start) indefinitely. ctr version hangs / connection error. After TimeoutStartSec (90s in our setup) systemd kills + restarts → fails identically, forever. Journal repeats every cycle:

start operation timed out. Terminating.
Failed with result 'timeout'.
Scheduled restart job, restart counter is at N.

Node goes NotReady. CRI down → kubelet can't create/kill/exec any pod. Only CRI-independent host-network pods (CNI, node-local DNS, CSI node plugins) keep running; everything else gets stuck Terminating or unschedulable.

Debugging we've done (ruled out systematically)

  • Disk/inodes: 9% used, 789G free, 2% inodes — not a space issue.
  • runsc debug logs filling disk: /var/log/runsc only 134MB / ~4,890 files, no ENOSPC anywhere.
  • Hung CephFS mount blocking cleanup: stat -f returned instantly, mount responsive.
  • Procs stuck in kernel (D state): none found (ps -eo pid,stat,wchan,cmd).
  • Wedged gVisor Sentry: runsc ... debug --stacks returned immediately, clean idle goroutines.
  • Deadlocked gVisor shims: ~2 dozen runsc shims sampled, all idle waiting-for-work, none stuck.
  • Unread data on a socket: ss -xp showed empty rx/tx queues on both ends.
  • Just wait longer: raised TimeoutStartSec to 900s on a staging node — still never finished. Looks like it's waiting on something that will never happen, not something slow.

Live dump via kill -SIGUSR1 <containerd-pid> (debug socket was off; with it on, ctr pprof goroutines gives the same info). Two dumps a couple minutes apart across a kill/restart cycle, identical: ~a dozen threads permanently parked "waiting for a response" — containerd reaching out to a leftover shim to confirm/finalize its task is gone, reply never comes.

What we believe is happening (from the dumps; confirmed directly by repro B)

On startup, containerd walks every leftover task/shim dir and, for the ones it thinks are abandoned (no running process found), sends each a cleanup/confirmation request and waits with no timeout before moving on. If even one shim never replies to that one request, startup hangs forever → systemd start-timeout kill → restart → same hang, because the blocker hasn't gone. Repro B shows this is unconditional: it doesn't matter why the shim doesn't answer, only that it doesn't.

We still don't know why the real production shims never reply — we couldn't catch one in the act; by the time we looked, only containerd's side was visibly stuck. Repro B proves the containerd-side mechanism, not the shim-side root cause. gVisor's tracker has gvisor/gvisor#9383 (gVisor processes stuck/unresponsive while appearing alive), which might be related — unconfirmed, just flagging it.

Workaround (not a fix)

Stop containerd + kubelet, force-kill leftover shim/runsc procs, and clear /run/containerd/* (tmpfs runtime state only — we do not touch /var/lib/containerd), then restart. Healthy immediately. But the same workloads rebuild the same leftover state, so the next unrelated containerd restart can hit this again.

Happy to gather more diagnostics — we still have an affected node in its stuck state as of writing.

Show configuration if it is related to CRI plugin.

/etc/containerd/config.toml

imports = ["/etc/containerd/conf.d/*.toml"]
version = 4
root = "/var/lib/containerd"
state = "/run/containerd"
oom_score = 0

[grpc]
  max_recv_message_size = 16777216
  max_send_message_size = 16777216

[debug]
  address = ""
  level = "info"
  format = ""
  uid = 0
  gid = 0

[metrics]
  address = ""
  grpc_histogram = false

[plugins]
  [plugins."io.containerd.cri.v1.runtime"]
    max_container_log_line_size = 16384
    enable_unprivileged_ports = false
    enable_unprivileged_icmp = false
    enable_selinux = false
    disable_apparmor = false
    tolerate_missing_hugetlb_controller = true
    disable_hugetlb_controller = true
    enable_cdi = true
    cdi_spec_dirs = ["/etc/cdi", "/var/run/cdi"]

   [plugins."io.containerd.cri.v1.runtime".containerd]
     default_runtime_name = "runc"
     [plugins."io.containerd.cri.v1.runtime".containerd.runtimes]
       [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc]
         runtime_type = "io.containerd.runc.v2"
         base_runtime_spec = "/etc/containerd/cri-base.json"

         [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc.options]
           Root = ""
           SystemdCgroup = true
           BinaryName = "/usr/local/bin/runc"

  [plugins."io.containerd.cri.v1.images"]
    snapshotter = "overlayfs"
    image_pull_progress_timeout = "5m"
  [plugins."io.containerd.cri.v1.images".pinned_images]
    sandbox = "registry.k8s.io/pause:3.10.2"
  [plugins."io.containerd.cri.v1.images".registry]
    config_path = "/etc/containerd/certs.d"

  [plugins."io.containerd.nri.v1.nri"]
    disable = false

/etc/containerd/runsc.toml

[runsc_config]
  platform = "systrap"
  debug = "true"
  debug-log = "/var/log/runsc/"
  overlay2 = "all:self"

/etc/containerd/conf.d/98-runsc.toml

version = 2
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc]
  runtime_type = "io.containerd.runsc.v1"
  pod_annotations = ["dev.gvisor.*", "dev.gvisor.io/*"]
  container_annotations = ["dev.gvisor.*", "dev.gvisor.io/*"]
  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc.options]
    TypeUrl = "io.containerd.runsc.v1.options"
    ConfigPath = "/etc/containerd/runsc.toml"

Activity

  1. added a commit that references this issue on Jul 25, 2026
    6f33a01
  2. Ayush-Rathor commented on Jul 31, 2026

    @Ayush-Rathor
    Author

    Update

    Since filing, we've confirmed both a start-side and a stop-side hang. They share one root condition. #13852 fixes the start side; we've opened a companion PR #13877 for the stop side.

    #13852 is correct (start-side)

    • Wrapping shim.delete() in loadShims with the existing 5s cleanup timeout matches the call site we traced this to.
    • It's the right fix for the startup hang described here — but it only covers the start path.

    The shared root condition

    Both hangs are unbounded waits tripping over the same shim state:

    • Shim process is still alive and reachable on the socket.
    • Sandbox is confirmed gone — runsc ... debug --stacks <id> returns immediately with container sandbox is not running (no hang, no timeout).
    • The shim then never replies to any request containerd sends it.

    Where each call site hits it:

    • Start: loadShims → Delete call.
    • Stop: getTasksMetrics → Stats call (same shim, same state).
    • Neither had a timeout, so either can hang forever.

    What we know vs. don't:

    • Confirmed: a shim in this state answers no request, which is why both sites needed fixing.
    • Still open: why the shim enters this state (likely a gVisor-side question, not containerd).

    Stop-side hang (#13852 doesn't cover this)

    • In the same incident, graceful stop hung for the full stop timeout before systemd SIGKILLed it. Only then did the start-side hang kick in on next boot.
    • Cause: getTasksMetrics in plugins/services/tasks/local.go calls tk.Stats(ctx) per task, sequentially, with no timeout.
    • The CRI plugin's StatsCollector calls this once/second from a background goroutine. Its Stop() blocks on that goroutine, which only checks for stop between cycles.
    • So one hung Stats() wedges the whole loop: all tasks stop getting metrics, and StatsCollector.Stop() (called from criService.Close()) never returns.
    • Companion PR opened here plugins/services/tasks: add timeout to per-task Stats() call in getTasksMetrics #13877 . Posting both together so the full picture is visible.

    Repro attempt — no live repro, but informative

    Tested with gVisor:

    • Ran full lifecycle churn (create → start → run → exit → delete) via crictl and the Kubernetes API on a bare-metal worker node.
    • ~2,850 synthetic cycles + organic churn, across 4 containerd restarts — every restart resolved cleanly in seconds, including ones cleaning up dozens of leftover shims (28 in one case, 7 in another).
    • Live scan of all running gVisor shims found them healthy and responsive every time we checked.

    Takeaway: this is a rare timing window, not readily reproducible even under heavy churn — consistent with our incident (only 5 shims stuck out of a large population).

    Happy to share raw evidence (goroutine dumps, journal captures, aggregation script/output) if useful for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions