Skip to content

CRI plugin: container stuck as RUNNING after process exit #12678

Closed as not planned

Description

@evgfitil

Description

After a failed liveness probe, kubelet initiated container termination via StopContainer CRI call. The termination process involved multiple retry attempts, each failing with context canceled or DeadlineExceeded. Eventually, the container process was killed (SIGKILL sent at 10:39:32), the shim was removed, and the cgroup was deleted.

However, after all physical resources were cleaned up, querying the container state reveals a state inconsistency:

  • ctr tasks ls correctly shows STOPPED
  • crictl inspect incorrectly shows CONTAINER_RUNNING with finishedAt unset (zero time)

As a result, kubelet continues to call StopContainer in an infinite loop, receiving DeadlineExceeded errors because it's trying to stop a container that no longer exists. The pod remains stuck in Terminating state indefinitely.

The only recovery is to restart containerd.

Environment

  • containerd: 1.7.27 (commit 05044ec)
  • runc: 1.2.5
  • Kubernetes: 1.31.2

Observed State

containerd task API shows STOPPED:

$ ctr -n k8s.io tasks ls | grep acaca462a89ac
acaca462a89acd5d959f9598c8d47ce7f72e32fc86f13827f6fbeb7e5d1cd424    4758    STOPPED

CRI API shows RUNNING:

$ crictl inspect acaca462a89ac | jq -r '.status.state, .status.finishedAt'
CONTAINER_RUNNING
0001-01-01T00:00:00Z

Physical resources are all cleaned up:

# Process does not exist
$ ls /proc/4758
ls: cannot access '/proc/4758': No such file or directory

# Shim removed
$ ps aux | grep containerd-shim | grep acaca462a89ac
(no output)

# Cgroup deleted
$ ls /sys/fs/cgroup/kubepods/burstable/pod39ea.../acaca462a89ac...
ls: cannot access: No such file or directory

Timeline

Time Component Event
10:36:31 kubelet StopContainer failed: DeadlineExceeded
10:36:31 kubelet "Container kube-controller-manager failed liveness probe, will be restarted"
10:36:31 kubelet "Killing container with grace period 30s"
10:39:01 kubelet StopContainer failed: DeadlineExceeded (retry)
10:39:01 containerd StopContainer failed: context canceled
10:39:02 containerd StopContainer with timeout 30s
10:39:32 containerd SIGKILL sent
10:41:32 containerd StopContainer failed: context canceled
10:41:32 containerd "Skipping the sending of signal terminated... because a prior stop already sent the signal"

Logs

kubelet:

Oct 14 10:36:31 kubelet[8345]: E1014 10:36:31.256309 "StopContainer from runtime service failed" err="rpc error: code = DeadlineExceeded desc = context deadline exceeded" containerID="acaca462a89ac"
Oct 14 10:36:31 kubelet[8345]: I1014 10:36:31.605638 "Message for Container of pod" containerMessage="Container kube-controller-manager failed liveness probe, will be restarted"
Oct 14 10:36:31 kubelet[8345]: I1014 10:36:31.605725 "Killing container with a grace period" containerName="kube-controller-manager" gracePeriod=30
Oct 14 10:39:01 kubelet[8345]: E1014 10:39:01.613275 "StopContainer from runtime service failed" err="rpc error: code = DeadlineExceeded desc = context deadline exceeded" containerID="acaca462a89ac"
Oct 14 10:39:02 kubelet[8345]: I1014 10:39:02.176566 "Message for Container of pod" containerMessage="Container kube-controller-manager failed liveness probe, will be restarted"
Oct 14 10:39:02 kubelet[8345]: I1014 10:39:02.176763 "Killing container with a grace period" containerName="kube-controller-manager" gracePeriod=30

containerd:

Oct 14 10:39:01 containerd[7758]: level=error msg="StopContainer for \"acaca462a89ac\" failed" error="rpc error: code = Canceled desc = an error occurs during waiting for container to be killed: context canceled"
Oct 14 10:39:02 containerd[7758]: level=info msg="StopContainer for \"acaca462a89ac\" with timeout 30 (s)"
Oct 14 10:39:32 containerd[7758]: level=info msg="Kill container \"acaca462a89ac\""
Oct 14 10:41:32 containerd[7758]: level=error msg="StopContainer for \"acaca462a89ac\" failed" error="rpc error: code = Canceled desc = an error occurs during waiting for container to be killed: context canceled"
Oct 14 10:41:32 containerd[7758]: level=info msg="StopContainer for \"acaca462a89ac\" with timeout 30 (s)"
Oct 14 10:41:32 containerd[7758]: level=info msg="Skipping the sending of signal terminated to container \"acaca462a89ac\" because a prior stop with timeout>0 request already sent the signal"

Related Issues

Expected Behavior

CRI plugin should update container status to EXITED when the container process terminates, regardless of whether the initiating gRPC context was cancelled.

Activity

  1. added
    area/cri
    on Dec 12, 2025
  2. ningmingxiao commented on Dec 12, 2025

    @ningmingxiao
    Contributor

    cat you kill -10 pidof containerd to print stack at /tmp/ @evgfitil

  3. ningmingxiao commented on Dec 12, 2025

    @ningmingxiao
    Contributor

    can you see "received exit event" log and show log about acaca462a8 @evgfitil

  4. evgfitil commented on Dec 22, 2025

    @evgfitil
    Author

    @ningmingxiao thank you for the guidance. The issue reproduced again on a different cluster. This bug is flaky - it depends on specific timing of context cancellations during overlapping StopContainer calls, which makes it hard to catch in the act

    Answers to your questions

    1. Stack dump - collected, see below. Key finding: goroutine 271158 is stuck in waitContainerStop at container_stop.go:210;
    2. "received exit event" log - not present in logs. The grep output below shows container activity, but no exit event was ever logged:
      $ journalctl -u containerd --since "1 hour ago" | grep -E "(received exit event|TaskExit|efd00be6ff246)"
      Dec 22 15:21:04 cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:21:04.445265714Z" level=info msg="Kill container \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\""
      Dec 22 15:23:04 cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:23:04.444064692Z" level=error msg="StopContainer for \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\" failed" ...
      Dec 22 15:23:05 cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:23:05.002107597Z" level=info msg="StopContainer for \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\" with timeout 30 (s)"
      Dec 22 15:23:05 cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:23:05.002618287Z" level=info msg="Skipping the sending of signal terminated ..."
      # Note: no "received exit event" or "TaskExit" entries present
    
    1. Stack are here https://gist.github.com/evgfitil/42be5e15b7c1e705f774d49fe204c4d8

    New reproduction details

    Container ID: efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457

    kubelet logs:

      Dec 22 15:15:32 cato81vjtq65gdje6rra-a kubelet[9478]: E1222 15:15:32.202566    9478 pod_workers.go:1301] "Error syncing pod, skipping" err="failed to KillContainer for kube-controller-manager with KillContainerError: rpc error: code = DeadlineExceeded desc = context deadline exceeded" pod="kube-system/kube-controller-manager-mk8s-master-cato81vjtq65gdje6rra-a" podUID="914777ed08a5f68982cce73cff843aff"
      Dec 22 15:15:32 cato81vjtq65gdzie6rra-a kubelet[9478]: I1222 15:15:32.901200    9478 kubelet.go:3200] "Creating a mirror pod for static pod" pod="kube-system/kube-controller-manager-mk8s-master-cato81vjtq65gdzie6rra-a"
      Dec 22 15:15:32 cato81vjtq65gdzie6rra-a kubelet[9478]: I1222 15:15:32.901388    9478 kuberuntime_manager.go:1094] "Message for Container of pod" containerName="kube-controller-manager" containerStatusID={"Type":"containerd","ID":"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457"} pod="kube-system/kube-controller-manager-mk8s-master-cato81vjtq65gdzie6rra-a" containerMessage="Container kube-controller-manager failed liveness probe, will be restarted"
      Dec 22 15:15:32 cato81vjtq65gdzie6rra-a kubelet[9478]: I1222 15:15:32.901449    9478 kuberuntime_container.go:809] "Killing container with a grace period" pod="kube-system/kube-controller-manager-mk8s-master-cato81vjtq65gdzie6rra-a" podUID="914777ed08a5f68982cce73cff843aff" containerName="kube-controller-manager" containerID="containerd://efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457" gracePeriod=30
    

    containerd logs:

      Dec 22 15:21:04 cato81vjtq65gdzie6rra-a containerd[8931]: time="2025-12-22T15:21:04.445265714Z" level=info msg="Kill container efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457"
      Dec 22 15:23:04 cato81vjtq65gdzie6rra-a containerd[8931]: time="2025-12-22T15:23:04.444064692Z" level=error msg="StopContainer for efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457 failed" error="rpc error: code = Canceled desc = an error occurs during waiting for container efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457 to be killed: wait container efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457: context canceled"
      Dec 22 15:23:05 cato81vjtq65gdzie6rra-a containerd[8931]: time="2025-12-22T15:23:05.002107597Z" level=info msg="StopContainer for efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457 with timeout 30 (s)"
      Dec 22 15:23:05 cato81vjtq65gdzie6rra-a containerd[8931]: time="2025-12-22T15:23:05.002618287Z" level=info msg="Skipping the sending of signal terminated to container efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457 because a prior stop with timeout>0 request already sent the signal"
    

    state inconsistency:

    $ ctr -n k8s.io tasks ls | grep efd00be6ff246
    efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457    4249     STOPPED
    
    $ crictl inspect efd00be6ff246 | jq '{state: .status.state, finishedAt: .status.finishedAt}'
    {
      "state": "CONTAINER_RUNNING",
      "finishedAt": "0001-01-01T00:00:00Z"
    }
  5. ningmingxiao commented on Dec 23, 2025

    @ningmingxiao
    Contributor

    can you show container efd00be6ff246 process tree ( should include shim process )? @evgfitil

  6. evgfitil commented on Dec 23, 2025

    @evgfitil
    Author

    can you show container efd00be6ff246 process tree ( should include shim process )? @evgfitil

    Perhaps I misunderstood the question, but the shim process and container process no longer exist

      # ctr shows task as STOPPED with PID 4249
      $ ctr -n k8s.io tasks ls | grep efd00be6ff246
      efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457    4249     STOPPED
    
      # Process does not exist
      $ pstree 4249
      (no output)
    
      # Shim does not exist
      $ ps aux | grep containerd-shim | grep efd00be6ff246
      (no output)
    
      # /proc confirms process is gone
      $ ls /proc/4249
      ls: cannot access '/proc/4249': No such file or directory
  7. ningmingxiao commented on Dec 23, 2025

    @ningmingxiao
    Contributor

    cat containerd.log | grep efd00be6ff2|grep -i sandbox you can find sandbox id then ps -auxf show the tree that include sandboxid @evgfitil

  8. ningmingxiao commented on Dec 24, 2025

    @ningmingxiao
    Contributor

    can you show the error detail (the error is omitted) and containerd start time @evgfitil

    Dec 22 15:23:04 cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:23:04.444064692Z" level=error msg="StopContainer for \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\" failed" ...
    
  9. evgfitil commented on Dec 24, 2025

    @evgfitil
    Author

    cat containerd.log | grep efd00be6ff2|grep -i sandbox you can find sandbox id then ps -auxf show the tree that include sandboxid @evgfitil

    # journalctl -u containerd | grep efd00be6ff2 | grep -i sandbox
    Dec 22 08:25:42 mk8s-master-cato81vjtq65gdje6rra-a containerd[2742]: time="2025-12-22T08:25:42.451971793Z" level=info msg="CreateContainer within sandbox \"1e572e371717022028b25b67ef10137e4689edd8a8c143bbbb21b0d05f32001c\" for &ContainerMetadata{Name:kube-controller-manager,Attempt:0,} returns container id \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\""
    # ps -auxf | grep 1e572e371717
    root     1405609  0.0  0.0   8172   656 pts/0    S+   06:30   0:00                      \_ grep --color=auto 1e572e371717
    root        3045  0.0  0.1 1238360 14156 ?       Sl   Dec22   1:29 /usr/bin/containerd-shim-runc-v2 -namespace k8s.io -id 1e572e371717022028b25b67ef10137e4689edd8a8c143bbbb21b0d05f32001c -address /run/containerd/containerd.sock

    can you show the error detail (the error is omitted) and containerd start time

    Dec 22 15:23:04 mk8s-master-cato81vjtq65gdje6rra-a containerd[8931]: time="2025-12-22T15:23:04.444064692Z" level=error msg="StopContainer for \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\" failed" error="rpc error: code = Canceled desc = an error occurs during waiting for container \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\" to be killed: wait container \"efd00be6ff246a778fe2c045916f51e3bef3fc6e8a1443b57292e9e7a8a69457\": context canceled"
  10. ningmingxiao commented on Dec 24, 2025

    @ningmingxiao
    Contributor

    can you show pid 3045 child process status ? (use ps -auxf )and systemctl status containerd @evgfitil

  11. evgfitil commented on Dec 24, 2025

    @evgfitil
    Author

    can you show pid 3045 child process status ? (use ps -auxf )and systemctl status containerd

    https://gist.github.com/evgfitil/6c4186c79fbf33fbb7e5dd613ad386ca

  12. ningmingxiao commented on Dec 24, 2025

    @ningmingxiao
    Contributor

    you don't need grep I want to see it's child process @evgfitil

  13. 28 remaining items

  14. added 5 commits that reference this issue on Jun 7, 2026
    67826e9
    2f91df4
    68681c2
    078fec4
    9cca3d1
  15. dosubot commented on Aug 15, 2026

    @dosubot

    Hi, @evgfitil. I'm Dosu, and I'm helping the containerd team manage their backlog and am marking this issue as stale.

    Issue Summary

    • You reported a flaky containerd 1.7.x issue where a failed liveness probe plus overlapping StopContainer calls can leave CRI metadata stuck at CONTAINER_RUNNING with no finishedAt.
    • The task, shim, and cgroup appear to be cleaned up, but the container wait path can remain blocked in pkg/process.(*Init).Wait.
    • Follow-up debugging showed StopContainer cancellations and no received exit event / TaskExit entries, which suggests the exit notification path is being missed.
    • You confirmed the behavior still reproduces on containerd 1.7.27 and appears separate from the restart/recovery bug fixed by PR [release/1.7] cri:fix lost container exit events if they arrive before info is cached #11634.
    • Additional logging was suggested in the reap/notify and shim exit-handling paths, and the issue has not yet been resolved.

    Next Steps

    • Please let us know if this is still relevant on the latest version of containerd; if so, you can keep the discussion open by commenting here.
    • Otherwise, this issue will be automatically closed in 7 days.

    Thanks for your understanding and contribution.

  16. github-actions commented on Aug 30, 2026

    @github-actions

    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.

  17. sgohl commented on Aug 31, 2026

    @sgohl

    Sorry for the AI slop, but I barely grasp the actual problem myself and required help to formulate a follow-up

    I believe this issue should be reopened.

    We are seeing the same CRI/containerd state inconsistency on a current K3s/Kubernetes stack under heavy short-lived CronJob workload.

    Environment:

    • K3s: v1.36.3+k3s1
    • containerd: v2.3.2-k3s2
    • CRI API: v1
    • Runtime: io.containerd.runc.v2
    • Workload: high churn of short-lived Kubernetes CronJobs, normally completing within approximately 5 seconds

    The main symptom is that completed containers remain reported as Running by Kubernetes and CRI for several minutes, even though the underlying containerd task has already stopped.

    Example:

    kubectl:
    
    phase: Running
    container state: running
    containerID:
    41133fb58cf51fa59f06f82703d25dd43cfe026cd0d765998c994111ed92bb1b
    

    For the same container:

    k3s crictl inspect 41133fb58cf51fa59f06f82703d25dd43cfe026cd0d765998c994111ed92bb1b
    
    state:      CONTAINER_RUNNING
    exitCode:   0
    startedAt:  2026-08-31T09:37:26.069529233Z
    finishedAt: 0001-01-01T00:00:00Z
    

    However, containerd already reports the task as stopped:

    k3s ctr -n k8s.io tasks ls
    
    41133fb58cf51fa59f06f82703d25dd43cfe026cd0d765998c994111ed92bb1b    12639    STOPPED
    

    So the state is:

    containerd task API: STOPPED
    CRI ContainerStatus: CONTAINER_RUNNING
    Kubernetes Pod:      Running
    

    This is essentially the same inconsistency described in #12678: the process/task has exited, but the CRI state is not updated to CONTAINER_EXITED, leaving finishedAt unset and causing kubelet to continue treating the container as running.

    We also see related sandbox cleanup failures:

    StopPodSandbox from runtime service failed
    rpc error: code = DeadlineExceeded desc = context deadline exceeded
    

    These occur repeatedly for old CronJob sandboxes.

    A directly executed CRI call reproduced the same problem:

    time k3s crictl stopp <sandbox-id>
    
    rpc error: code = DeadlineExceeded desc = context deadline exceeded
    

    The call failed after approximately two seconds.

    For affected sandboxes we observed another state inconsistency:

    processStatus:      stopped
    CRI sandbox state:  SANDBOX_READY
    netNamespaceClosed: false
    

    The corresponding containerd-shim-runc-v2 process was still present while the task itself was already:

    STOPPED
    

    There are also kubelet/cAdvisor errors related to disappearing or inconsistent container/cgroup state:

    Failed to create existing container:
    .../cri-containerd-<id>.scope:
    container not created: not found
    

    and:

    Failed to create existing container:
    .../cri-containerd-<id>.scope:
    context deadline exceeded
    

    This is reproducible across multiple worker nodes and affects a large number of short-lived CronJob containers.

    We initially suspected Kubernetes ImageVolume, SMB/NFS teardown, or CNI cleanup. However:

    • NFS and SMB volume teardown completes successfully.
    • The CNI network namespace and veth are valid and accessible.
    • Disabling ImageVolume on one worker did not resolve the main issue.
    • New containers created after the node restart still show the same ctr STOPPED / CRI RUNNING inconsistency.

    The important point is that this is not just a stale pod status in Kubernetes. The inconsistency exists directly inside containerd:

    ctr task state != CRI ContainerStatus state
    

    The original issue was reported against containerd 1.7.x. We can reproduce the same fundamental failure on containerd 2.3.2-k3s2.

    For that reason, I believe #12678 is still relevant and should be reopened, or alternatively linked to an active issue tracking the same CRI TaskExit/state propagation problem in containerd 2.x.

  18. ningmingxiao commented on Aug 31, 2026

    @ningmingxiao
    Contributor

    can you show containerd stack use kill -10 pidof containerd will print containerd stack at /tmp/ dir and show containerd log about 41133fb5 @sgohl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalearea/crikind/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions