Skip to content

Pod stays in terminating state and waiting for container to be stopped by containerd #10755

Closed

Description

@smoshiur1237

Description

We are trying a back-to-back installation and deletion of application (50pods) and in some iterations a few pods get stuck in Terminating state forever.

The containerd logs show a StopContainer failed error when trying to stop the container and it continues forever have repeated error many times.

Jun 26 07:44:44 containerd[1891085]: time="2024-06-26T07:44:44.559390176Z" level=error msg="StopContainer for \"256a184124d5b4715ef4caf2deab0b6a25ba338aa78805b6aa2b0a055eeb159c\" failed" error="rpc error: code = DeadlineExceeded desc = an error occurs during waiting for container \"256a184124d5b4715ef4caf2deab0b6a25ba338aa78805b6aa2b0a055eeb159c\" to be killed: wait container \"256a184124d5b4715ef4caf2deab0b6a25ba338aa78805b6aa2b0a055eeb159c\": context deadline exceeded"

And another test have similar error after few days:

Jun 30 19:49:39 containerd[4166223]: time="2024-06-30T19:49:39.401009033Z" level=error msg="StopContainer for \"c08d38b62a1d1f2d80d7be8383a5bf0398c296c42b4276b936f3b84eb7fbb6fa\" failed" error="rpc error: code = Canceled desc = an error occurs during waiting for container \"c08d38b62a1d1f2d80d7be8383a5bf0398c296c42b4276b936f3b84eb7fbb6fa\" to be killed: wait container \"c08d38b62a1d1f2d80d7be8383a5bf0398c296c42b4276b936f3b84eb7fbb6fa\": context canceled"
Jun 30 19:49:39 containerd[4166223]: time="2024-06-30T19:49:39.482845511Z" level=error msg="ExecSync for \"c08d38b62a1d1f2d80d7be8383a5bf0398c296c42b4276b936f3b84eb7fbb6fa\" failed" error="failed to exec in container: failed to start exec \"20291caecb3748213b74361fbde4ed2ce93c458c76897f6107e7cc7b84234b07\": OCI runtime exec failed: exec failed: cannot exec in a stopped container: unknown"

This never auto-recovers and the only way to recover from this issue is to restart containerd.

The crictl ps, shows that the related container in the list, we tried to exec in the container and it stays
OCI runtime exec failed: exec failed: cannot exec in a stopped container: unknown has exited
So it seems that container is stopped but was not deleted from running container list.

Steps to reproduce the issue

It is difficult to reproduce. But once it reproduced, it is giving consistent error on stop container.

  1. Doing multiple iteration of installation and deletion on 50 pods.
  2. Few pods stays in terminating state and containerd was generating StopContainer failure.

Describe the results you received and expected

When waitContainerStop() is giving error during timeout, stopContainer() function should handle it by logging the error and start to return the cleanupUnknownContainer() which should eventually remove the container. So Containerd should stop and remove the container. Pod shouldn't stayed in terminating state and got deleted.

What version of containerd are you using?

containerd v1.7.15 926c958

Any other relevant information

$ runc --version
runc version 1.1.12
commit: v1.1.12-0-g51d5e946
spec: 1.0.2-dev
go: go1.17.6
libseccomp: 2.5.3

Show configuration if it is related to CRI plugin.

No response

Activity

  1. ningmingxiao commented on Oct 5, 2024

    @ningmingxiao
    Contributor

    you can try this pr 421a4b5
    introduced by 892dc54

  2. samuelkarp commented on Oct 7, 2024

    @samuelkarp
    Member

    OCI runtime exec failed: exec failed: cannot exec in a stopped container: unknown

    This is most likely #10589, which is fixed in 1.7.22.

  3. smoshiur1237 commented on Oct 15, 2024

    @smoshiur1237
    Author

    @ningmingxiao @samuelkarp
    We have tried the fix that you have mentioned and we haven't seen the issue re-producible in our system. The solution here to use upgradedd version of containerd and containerd-shim-runc-v2 which is 1.7.22(have the fix), same time we also need to use runc- 1.1.14. Thanks for your information.
    So I am closing this issue. If we see the issue again, will re-open it.

  4. jzkinetic commented on Nov 13, 2024

    @jzkinetic

    I can confirm that this issue is not resolved.

    Here is a container that is stuck in "terminating" state in K8s.

    CONTAINER           IMAGE               CREATED             STATE               NAME                             ATTEMPT             POD ID              POD
    9292605de2272       43375676b50f5       3 hours ago         Running             swap-backend-container-dev       0                   74317c53a96b7       swap-backend-deployment-dev-6996d48787-htd4q
    

    ./crictl exec 9292605de2272 ls outputs:

    WARN[0000] runtime connect using default endpoints: [unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
    FATA[0000] execing command in container: Internal error occurred: error executing command in container: failed to exec in container: failed to create exec "614075b3f467d1f9d4d2a48500e4a507ec1564d3996b3069a5553dcd7abf8fbe": cannot exec in a stopped state: unknown
    

    ./crictl stopp 74317c53a96b7 outputs:

    WARN[0000] runtime connect using default endpoints: [unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
    E1113 02:43:00.527605   77836 log.go:32] "StopPodSandbox from runtime service failed" err="rpc error: code = DeadlineExceeded desc = context deadline exceeded" podSandboxID="74317c53a96b7"
    FATA[0002] stopping the pod sandbox "74317c53a96b7": rpc error: code = DeadlineExceeded desc = context deadline exceeded
    

    Have tried updating to latest version of containerd and runc, neither have worked.

    runc -v
    runc version 1.1.14
    commit: 2c9f5602f0ba3d9da1c2596322dfc4e156844890
    spec: 1.0.2-dev
    go: go1.22.5
    libseccomp: 2.5.3
    
    ctr -v
    ctr github.com/containerd/containerd 1.7.22
    
  5. ningmingxiao commented on Nov 13, 2024

    @ningmingxiao
    Contributor

    ctr -n k8s.io t ls |grep containerid
    kill -10 1111 (shimpid) print shim stack in containerd log.
    kill -10 pidof containerd print containerd stack in /tmp/

    @jzkinetic

  6. antoniotamer commented on Feb 21, 2025

    @antoniotamer

    I can confirm that this issue is not resolved.

    Here is a container that is stuck in "terminating" state in K8s.

    CONTAINER           IMAGE               CREATED             STATE               NAME                             ATTEMPT             POD ID              POD
    9292605de2272       43375676b50f5       3 hours ago         Running             swap-backend-container-dev       0                   74317c53a96b7       swap-backend-deployment-dev-6996d48787-htd4q
    

    ./crictl exec 9292605de2272 ls outputs:

    WARN[0000] runtime connect using default endpoints: [unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
    FATA[0000] execing command in container: Internal error occurred: error executing command in container: failed to exec in container: failed to create exec "614075b3f467d1f9d4d2a48500e4a507ec1564d3996b3069a5553dcd7abf8fbe": cannot exec in a stopped state: unknown
    

    ./crictl stopp 74317c53a96b7 outputs:

    WARN[0000] runtime connect using default endpoints: [unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
    E1113 02:43:00.527605   77836 log.go:32] "StopPodSandbox from runtime service failed" err="rpc error: code = DeadlineExceeded desc = context deadline exceeded" podSandboxID="74317c53a96b7"
    FATA[0002] stopping the pod sandbox "74317c53a96b7": rpc error: code = DeadlineExceeded desc = context deadline exceeded
    

    Have tried updating to latest version of containerd and runc, neither have worked.

    runc -v
    runc version 1.1.14
    commit: 2c9f5602f0ba3d9da1c2596322dfc4e156844890
    spec: 1.0.2-dev
    go: go1.22.5
    libseccomp: 2.5.3
    
    ctr -v
    ctr github.com/containerd/containerd 1.7.22
    

    I'm seeing the same issue. Almost the same containerd version (1.7.24), same scenario as the poster.

  7. samuelkarp commented on Feb 21, 2025

    @samuelkarp
    Member

    @jzkinetic @antoniotamer Please open a new issue if you are running into a new problem.

  8. ningmingxiao commented on Feb 21, 2025

    @ningmingxiao
    Contributor

    ctr -n k8s.io task ls show task status?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions