Repository navigation
Description
Description
After propagating kubelet's context to containerd, I encountered this issue in the CI environment of the k/k repo. This problem cannot be reproduced locally on my machine, but it is easily reproducible in the CI environment.
When kubelet propagates the context to containerd, if a pod is deleted rapidly during its creation process, kubelet cancels the context for the calls to containerd’s RunPodSandbox or StartContainer interfaces. As a result, the container becomes stuck in the runc init state, and the corresponding systemd scope for the container process cannot be terminated by systemd (the runc init process in this state does not respond to the SIGKILL signal sent by systemd).
Here are some relevant logs from containerd:
Apr 09 15:43:07 kind-worker containerd[952]: time="2025-04-09T15:43:07.960930948Z" level=info msg="connecting to shim 868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3" address="unix:///run/containerd/s/54e4e266685e59c354caa1f49a426289bb93552d0013e5d822eb1e1c223cc48e" namespace=k8s.io protocol=ttrpc version=3
Apr 09 15:43:13 kind-worker containerd[952]: time="2025-04-09T15:43:13.082478253Z" level=info msg="shim disconnected" id=868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3 namespace=k8s.io
Apr 09 15:43:13 kind-worker containerd[952]: time="2025-04-09T15:43:13.083329072Z" level=warning msg="cleaning up after shim disconnected" id=868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3 namespace=k8s.io
Apr 09 15:43:16 kind-worker containerd[952]: time="2025-04-09T15:43:16.441227228Z" level=warning msg="failed to cleanup rootfs mount" error="failed to unmount target /run/containerd/io.containerd.runtime.v2.task/k8s.io/868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3/rootfs: device or resource busy" runtime=io.containerd.runc.v2
Apr 09 15:43:17 kind-worker containerd[952]: time="2025-04-09T15:43:17.070374334Z" level=warning msg="cleanup warnings time=\"2025-04-09T15:43:17Z\" level=warning msg=\"failed to cleanup rootfs mount\" error=\"failed to unmount target /run/containerd/io.containerd.runtime.v2.task/k8s.io/868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3/rootfs: device or resource busy\" runtime=io.containerd.runc.v2\ntime=\"2025-04-09T15:43:17Z\" level=warning msg=\"failed to read init pid file\" error=\"open /run/containerd/io.containerd.runtime.v2.task/k8s.io/868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3/init.pid: no such file or directory\" runtime=io.containerd.runc.v2\n" namespace=k8s.io
Apr 09 15:43:17 kind-worker containerd[952]: time="2025-04-09T15:43:17.226334673Z" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:simpletest-rc-to-be-deleted-k2n2n,Uid:f0bf88c1-3599-4640-8b3d-85209a77809e,Namespace:gc-2542,Attempt:0,} failed, error" error="rpc error: code = Unknown desc = failed to start sandbox \"868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3\": failed to create containerd task: failed to create shim task: context canceled"
Apr 09 15:43:20 kind-worker containerd[952]: time="2025-04-09T15:43:20.638701034Z" level=warning msg="failed to clean up after shim disconnected" error="unmount rootfs /run/containerd/io.containerd.runtime.v2.task/k8s.io/868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3/rootfs: failed to unmount target /run/containerd/io.containerd.runtime.v2.task/k8s.io/868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3/rootfs: device or resource busy" id=868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3 namespace=k8s.io
Logs showing systemd’s inability to terminate the process:
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Stopping timed out. Killing.
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Killing process 240829 (runc:[2:INIT]) with signal SIGKILL.
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Killing process 240830 (runc:[2:INIT]) with signal SIGKILL.
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Killing process 240831 (runc:[2:INIT]) with signal SIGKILL.
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Killing process 240832 (runc:[2:INIT]) with signal SIGKILL.
Apr 09 15:44:55 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Killing process 240836 (runc:[2:INIT]) with signal SIGKILL.
...
Apr 09 15:46:25 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Still around after SIGKILL. Ignoring.
Apr 09 15:46:25 kind-worker systemd[1]: cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope: Failed with result 'timeout'.
Apr 09 15:46:25 kind-worker systemd[1]: Stopped cri-containerd-868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.scope - libcontainer container 868bcfae8373f4f43638e6b5b8aae6ca203395234a60300a8085905c1f69b2a3.
I also used ps -eo pid,stat,command to inspect processes on the Linux system, and there were no zombie processes:
+ docker exec kind-worker ps -eo pid,stat,command
PID STAT COMMAND
1 Ss /sbin/init
166 Ss /lib/systemd/systemd-journald
284 Ssl /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-log-max-files=10 --container-log-max-size=100Mi --container-runtime-endpoint=unix:///run/containerd/containerd.sock --node-ip=172.18.0.2 --node-labels= --pod-infra-container-image=registry.k8s.io/pause:3.10 --provider-id=kind://docker/kind/kind-worker --v=4 --runtime-cgroups=/system.slice/containerd.service
348 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id a560953f5ab686f4d518a758b9dad9d59fc0108ccd8d66e80c886a3f45b56ea5 -address /run/containerd/containerd.sock
392 Ss /pause
620 Ssl /bin/kindnetd
756 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 349ff3b7fc16bb4d1e0926b19ed4649d35e2b19d714b968b7c202f3e88b507f6 -address /run/containerd/containerd.sock
781 Ss /pause
807 Ssl /usr/local/bin/kube-proxy --config=/var/lib/kube-proxy/config.conf --hostname-override=kind-worker --v=4
952 Ssl /usr/local/bin/containerd
34876 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id a8b06c4c9b4d7d6217192bedbc82c62c1c297ab4849f1d759d35513787545afe -address /run/containerd/containerd.sock
92577 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id afe329cc8b61be6f73c4a2dd40fee0434da380ca95374fca3cdf3dbc4b178bb2 -address /run/containerd/containerd.sock
100436 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id e5c63633571d785b7d807e039c86f066f488f9aa258838d4a494db2f74da7af3 -address /run/containerd/containerd.sock
101082 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 896e7adfa1a26989b107cf6cdec4a0a3d3568c0cc947b37efa96c2210f5a7b0a -address /run/containerd/containerd.sock
144994 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id f8ca009809169cb021d0fd685e71b17e6b711cace4503285902822fe1d169c3f -address /run/containerd/containerd.sock
157103 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 6d9fa50aca9a901ae2aece6e23e175f7865dae0f05ce01d5d8ef75d3ca3c719c -address /run/containerd/containerd.sock
164087 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 3ab9c1cd8a2eb570dbcb92e82238845e7cb37d92c0a8a06ca89279205ff780c2 -address /run/containerd/containerd.sock
165484 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 546e26885cc0f36d2ba5daf932b022821638f66d15e36caa51410261c32689c8 -address /run/containerd/containerd.sock
214498 Ss /sbin/rpcbind -f -w
214508 Ss /sbin/rpc.statd
234086 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 663a7bed86bfb98883c5e5c437c7eded0d6a1c58dfda76ebb2996c5ca3647a5d -address /run/containerd/containerd.sock
240829 Rsl runc init
245320 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id c08574d614f0019a0d42a9700830eb9802d3d2da765fc4aeb2af019356b974bb -address /run/containerd/containerd.sock
245366 Sl /usr/local/bin/containerd-shim-runc-v2 -namespace k8s.io -id 7cc51ff73ecf1969b5984fab53bc4d1fd9d53c39ab2e8ddb38c4d638f85416e1 -address /run/containerd/containerd.sock
245834 Ss /pause
246702 Ssl /agnhost netexec --http-port=80 --delay-shutdown=300
292924 Rs ps -eo pid,stat,command
I only provided logs for canceling the context when calling the RunPodSandbox interface. Canceling the context during StartContainer yields the same result.
The place where I debugged this issue: kubernetes-sigs/kind#3903 (comment)
The PR in the Kubernetes/Kubernetes repo: kubernetes/kubernetes#127122 (it is responsible for passing the context to containerd)
When containerd receives a request to create a container (whether a sandbox or application container), it initializes the container using the runc init process. This process waits for runc start (the container startup interface) to activate the container and signal runc init to proceed. However, if the context is canceled, the runc init process may fail to continue execution or perform cleanup.
I am uncertain whether this is an issue with containerd or potentially runc: the runc init process might not properly handle stop signals in this pre startup state.
As a higher-level runtime, containerd’s responsibilities should include handling cancellation operations and cleaning up partial states (as I assume). Even though the shim is disconnected, containerd fails to unmount the rootfs and terminate the runc init process, indicating flaws in its error handling or cleanup logic.
I sincerely sorry, but since I’ve been unable to reproduce this issue locally, I cannot provide more useful information. I suspect that this issue may ultimately prevent systemd from shutting down properly, causing the kind container to fail to terminate normally, which is also how I discovered this problem.
EDIT:
I inspected the stack and wchan of the runc init process and obtained the following results:
+ echo [Kernel Stack Trace (/proc/27453/stack)]
[Kernel Stack Trace (/proc/27453/stack)]
+ docker exec kind-worker cat /proc/27453/stack
[<0>] __refrigerator+0xcd/0x150
[<0>] get_signal+0x5e2/0x960
[<0>] arch_do_signal_or_restart+0x39/0x120
[<0>] syscall_exit_to_user_mode+0x206/0x260
[<0>] do_syscall_64+0x8c/0x180
[<0>] entry_SYSCALL_64_after_hwframe+0x78/0x80
+ echo [Wait Channel (/proc/27453/wchan)]
[Wait Channel (/proc/27453/wchan)]
+ docker exec kind-worker cat /proc/27453/wchan
__refrigerator
Based on the above results, it indicates that the runc init process is currently frozen and cannot receive SIGTERM or SIGKILL until its frozen state is lifted.
Note: At this time, the process state is not D but Rsl.
Steps to reproduce the issue
Describe the results you received and expected
After the container creation is terminated, the container in the runc init state can be reclaimed by containerd or systemd.
What version of containerd are you using?
containerd github.com/containerd/containerd/v2 0148451 0148451
Any other relevant information
No response
Show configuration if it is related to CRI plugin.
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
yylt commentedon Apr 15, 2025
generelly some workload had mounted the rootfs and was holding open files in a container's mount namespace, look lilke it happeded due to
runc initholding file descriptors and resulting in the failure to unmount rootfs.0148451, Is this modification causing the problem, or can be recovery when meet problem?
HirazawaUi commentedon Apr 15, 2025
I'm surprised you found this commit in my personal repository.
This is some rough code I quickly put together after initially encountering the issue, trying to fix it. However, this code doesn't improve the problem at all, and after reviewing it again, I've determined that the direction for solving the problem isn't here.
I committed it to my own repo simply for the convenience of building it on the Linux platform, rather than intending it as a potential solution to seek other opinions on.
yylt commentedon Apr 16, 2025
This seems the runc blocking on some system call, usually in
uninterruptiblestate, which cause not respond to thekillsignal.Additionally, it would be helpful to print
/proc/{runc pid}/stack. Also, what version is runc?HirazawaUi commentedon Apr 16, 2025
Yes, that's what I suspected, but as I mentioned, I can't easily access the CI environment of the k/k repo, so the information I have is very limited. I'm trying to reproduce it locally by directly calling the containerd interface, while also opening an issue on the containerd repo to gather more suggestions and help ^_^.
BenTheElder commentedon Apr 16, 2025
It should be runc 1.2.5 currently:
https://github.com/kubernetes-sigs/kind/blob/1e95d05eeccdf615e24d7af11276e2954fe265a2/images/base/Dockerfile#L143
Sorry I don't have a lot of time to follow up on this right now.
You could dump the stack info from the CI scripts, though I imagine that's going to be a little bit annoying to script in advance versus interactively debugging.
dosubot commentedon Jul 17, 2026
Hi, @HirazawaUi. I'm Dosu, and I'm helping the containerd team manage their backlog and am marking this issue as stale.
Issue Summary
runc initpreventing the container’s systemd scope from being cleaned up.runc init, or thatrunccould be blocked in an uninterruptible syscall.runc1.2.5 and asked for stack information from CI, but the issue remains unresolved.Next Steps
Thanks for your understanding and contribution.
github-actions commentedon Aug 1, 2026
This issue was closed because it has been stale for 2 weeks with no activity. Feel free to reopen or create a new issue if you would like to continue working on it.