Repository navigation
Description
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)
- Run containerd 2.2.2/2.3.1 as CRI with gVisor registered alongside runc, state dir on tmpfs.
- Run workloads that restart frequently under gVisor over time → leftover shims whose tasks already exited but haven't been cleaned up.
- Restart containerd for any reason (we couldn't identify the original trigger on any of the three nodes).
- containerd never finishes starting: no socket,
ctr versionhangs, 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:
- Spare/non-prod node, containerd with runc as default.
- Start a container in its own namespace → running task + shim.
- Kill the task's main process directly (not via containerd) → task exits, shim left with nothing to manage.
- 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.)
- Restart containerd.
- Result: hung exactly as above — stuck at
activatingfor the full startup timeout, killed by systemd, restarted, stuck identically on the next attempt. Removing the relay → recovered on the following restart. - 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/runsconly 134MB / ~4,890 files, noENOSPCanywhere. - Hung CephFS mount blocking cleanup:
stat -freturned instantly, mount responsive. - Procs stuck in kernel (
Dstate): none found (ps -eo pid,stat,wchan,cmd). - Wedged gVisor Sentry:
runsc ... debug --stacksreturned immediately, clean idle goroutines. - Deadlocked gVisor shims: ~2 dozen
runscshims sampled, all idle waiting-for-work, none stuck. - Unread data on a socket:
ss -xpshowed empty rx/tx queues on both ends. - Just wait longer: raised
TimeoutStartSecto 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"Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
core/runtime/v2: add timeout to shim.delete during loadShims
Ayush-Rathor commentedon Jul 31, 2026
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)
shim.delete()inloadShimswith the existing 5s cleanup timeout matches the call site we traced this to.The shared root condition
Both hangs are unbounded waits tripping over the same shim state:
runsc ... debug --stacks <id>returns immediately withcontainer sandbox is not running(no hang, no timeout).Where each call site hits it:
loadShims→Deletecall.getTasksMetrics→Statscall (same shim, same state).What we know vs. don't:
Stop-side hang (#13852 doesn't cover this)
systemdSIGKILLed it. Only then did the start-side hang kick in on next boot.getTasksMetricsinplugins/services/tasks/local.gocallstk.Stats(ctx)per task, sequentially, with no timeout.StatsCollectorcalls this once/second from a background goroutine. ItsStop()blocks on that goroutine, which only checks for stop between cycles.Stats()wedges the whole loop: all tasks stop getting metrics, andStatsCollector.Stop()(called fromcriService.Close()) never returns.Repro attempt — no live repro, but informative
Tested with gVisor:
crictland the Kubernetes API on a bare-metal worker node.containerdrestarts — every restart resolved cleanly in seconds, including ones cleaning up dozens of leftover shims (28 in one case, 7 in another).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.