Skip to content

Wrongly classified "leaked shim" causes leaked container on containerd restart #13784

Closed

Description

@halaney

Description

When running a pod with a container that has writable cgroups
restarting containerd can sometimes incorrectly claim the
shim has been leaked, and this leads to orphaning the shim
and container. Kubelet spawns a replacement (assuming your restart
policy is setup so) and both workloads can live on.

I noticed this on a node I have that recently restarted containerd
as part of a system upgrade. The referenced container had been
running for days so far:

start-kubelet-containerd.sh[1884948]: {"id":"e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b","level":"info","msg":"cleaning leaked shim process","namespace":"k8s.io","time":"2026-07-08T18:47:39.948389522Z"}
start-kubelet-containerd.sh[1884948]: {"error":"rpc error: code = Unknown desc = cannot delete a running process","id":"e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b","level":"error","msg":"failed to delete task","namespace":"k8s.io","time":"2026-07-08T18:47:39.948779237Z"}

Inspecting that shim some shows its still around as well as the container
processes, but containerd knows nothing about it any more:

$ cat /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podb9724ab9_6bef_4951_a092_a9b1ddb4b682.slice/cri-containerd-e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b.scope/init.scope/cgroup.procs
1207102

$ ps elf 1207102
F   UID     PID    PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4 -1883963392 1207102 1206821 20 0 165844 9984 -    Ss   ?         61:53 /sbin/init
$ ps elf 1206821
F   UID     PID    PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
0     0 1206821       1  20   0 1245520 16380 -     Sl   ?         80:13 /apps/nflx-containerd/bin/
$ sudo crictl ps | grep e210df
$ sudo tctr -n k8s.io containers ls | grep e210df84
$ sudo tctr -n k8s.io tasks ls | grep e210df84

If you dive into that code path in containerd, it calls to the shim
and ultimately the shim does a runc ps. If it finds no pids, or errors out
at all, it claims leaked and takes the path already described. Let's mimic
that some:

$ sudo runc --root /run/containerd/runc/k8s.io ps e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b
UID          PID    PPID  C STIME TTY          TIME CMD
2411003+ 1207102 1206821  0 Jul03 ?        01:02:33 /sbin/init
(...)

$ sudo cat /run/containerd/io.containerd.runtime.v2.task/k8s.io/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b/bootstrap.json
{"version":3,"address":"unix:///run/containerd/s/010893ea6ff3e95972858a6dd7ac1e5c892b94085a6d4626cb26d91bb8591ef1","protocol":"ttrpc"}
$ sudo ctr -n k8s.io shim --shim-address unix:///run/containerd/s/010893ea6ff3e95972858a6dd7ac1e5c892b94085a6d4626cb26d91bb8591ef1 state --task-id e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b
{
    "id": "e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b",
    "bundle": "/run/containerd/io.containerd.runtime.v2.task/k8s.io/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b",
    "pid": 1207102,
    "status": 2,
    "stdout": "/run/containerd/io.containerd.grpc.v1.cri/containers/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b/io/3949225944/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b-stdout",
    "stderr": "/run/containerd/io.containerd.grpc.v1.cri/containers/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b/io/3949225944/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b-stderr",
    "exited_at": {
	"seconds": -62135596800
    }
}

So the shim is alive and well and this all worked fine. But finally I realized
the runc logs also make it to disk (but not journald):

(nfsuper) ~ $ sudo cat /run/containerd/io.containerd.runtime.v2.task/k8s.io/e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b/log.json
{"level":"error","msg":"unable to get all container pids: openat2 /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podb9724ab9_6bef_4951_a092_a9b1ddb4b682.slice/cri-containerd-e210df84bcd26056a76e73c9a07dac85c876f8b95776afa4b8d998f35986f25b.scope/system.slice/system-nodequark\\x2dlog.slice/[email protected]/cgroup.procs: no such file or directory","time":"2026-07-08T18:47:39Z"}

And that clears everything up. The container was deleting a cgroup while runc ps
happened, that errored, and we handled it poorly.

Steps to reproduce the issue

  1. Run a container with writable cgroups
  2. Delete cgroups rapidly
  3. Restart containerd

Describe the results you received and expected

Shim/container not orphaned

What version of containerd are you using?

2.2.1

Any other relevant information

No response

Show configuration if it is related to CRI plugin.

No response

Activity

  1. added a commit that references this issue on Jul 13, 2026
  2. halaney commented on Jul 13, 2026

    @halaney
    Author

    ^ you could say this is a runc bug, and yes probably needs improving there hence the PR. But I am also looking at how we could have made this more clear in containerd and prevented running an orphaned container like this alongside a new one, which is a pretty bad failure mode imo!

  3. chrishenzie commented on Jul 18, 2026

    @chrishenzie
    Member

    It looks like this issue could affect any container with writable cgroups (e.g.privileged, or created with the cgroup_writable config field enabled). Left some comments on the PR. It would be good to get this opencontainers/cgroups in a release, updated in runc, and backported to their supported release branches

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