Skip to content

*: properly shutdown non-groupable shims to prevent resource leaks#11916

Merged
fuweid merged 1 commit intocontainerd:mainfrom
fuweid:fix-11871
Jun 8, 2025
Merged

*: properly shutdown non-groupable shims to prevent resource leaks#11916
fuweid merged 1 commit intocontainerd:mainfrom
fuweid:fix-11871

Conversation

@fuweid
Copy link
Copy Markdown
Member

@fuweid fuweid commented May 30, 2025

Previously, to address issue #11708, PR #11793 changed containerd to always
invoke the shim binary to establish shim connections, rather than reusing the
sandbox shim. However, this change did not ensure that the Shutdown API was
called to stop the shim process.

Starting with containerd v2.0.0, the Shutdown API is only invoked for sandbox
containers (when container.SandboxID is empty). This approach works for
groupable shims, where multiple containers share a single socket address and
only require a single Shutdown call. However, for non-groupable shims, each
container requires its own Shutdown call during cleanup to avoid leaking shim
processes.

Additionally, PR #11793 introduced a corner case during upgrades:

  • T1: An old container-shim-runc-v2 (<=v1.7.X) is running for pod A.
  • T2: containerd is upgraded to v2.X.Y.
  • T3: A new container A-C1 is created in pod A using the new shim-runc-v2 binary.
  • T4: bootstrap.json indicates version:3 protocol, but it is downgraded to version:2 in memory.
  • T5: containerd is restarted.
  • T6: containerd fails to connect to A-C1.
  • T7: The A-C1 container is left in EXITED status in the CRI plugin.

To address this, ensure that loadShimTask downgrades to version:2 if necessary,
and always invoke the Shutdown API for each non-groupable shim during cleanup to
prevent resource leaks and handle upgrade scenarios correctly.

(Introduced by #11793)

Signed-off-by: Wei Fu [email protected]


Fixes: #11871

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented May 30, 2025

ping @smira if possible, would you please verify this patch? thanks
(I think this time I cover shim leaky issue in CI. but it's shim-runc-v1. just want to double confirm this patch can work with gvisor)

updated: tested with gvisor in my local. it can fix that issue.

@fuweid fuweid changed the title [WIP] Fix 11871 *: properly shutdown non-groupable shims to prevent resource leaks Jun 2, 2025
@fuweid fuweid requested review from dmcgowan, mxpv and samuelkarp June 2, 2025 03:57
Previously, to address issue containerd#11708, PR containerd#11793 changed containerd to always
invoke the shim binary to establish shim connections, rather than reusing the
sandbox shim. However, this change did not ensure that the Shutdown API was
called to stop the shim process.

Starting with containerd v2.0.0, the Shutdown API is only invoked for sandbox
containers (when container.SandboxID is empty). This approach works for
groupable shims, where multiple containers share a single socket address and
only require a single Shutdown call. However, for non-groupable shims, each
container requires its own Shutdown call during cleanup to avoid leaking shim
processes.

Additionally, PR containerd#11793 introduced a corner case during upgrades:
- T1: An old container-shim-runc-v2 (<=v1.7.X) is running for pod A.
- T2: containerd is upgraded to v2.X.Y.
- T3: A new container A-C1 is created in pod A using the new shim-runc-v2 binary.
- T4: bootstrap.json indicates version:3 protocol, but it is downgraded to version:2 in memory.
- T5: containerd is restarted.
- T6: containerd fails to connect to A-C1.
- T7: The A-C1 container is left in EXITED status in the CRI plugin.

To address this, ensure that loadShimTask downgrades to version:2 if necessary,
and always invoke the Shutdown API for each non-groupable shim during cleanup to
prevent resource leaks and handle upgrade scenarios correctly.

(Introduced by containerd#11793)

Signed-off-by: Wei Fu <[email protected]>
@fuweid fuweid added ok-to-test cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.1.x Change to be cherry picked to release/2.1 branch labels Jun 2, 2025
@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jun 2, 2025

/retest

@smira
Copy link
Copy Markdown
Contributor

smira commented Jun 3, 2025

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jun 3, 2025

@smira thanks for the update!

Comment thread core/runtime/v2/shim.go
removeTask(ctx, s.ID())
}

const supportSandboxAPIVersion = 3
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we move this to a package-level const and with comments about if/ when to bump up it? (also do we already have an existing const for the current API version?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fixed value. I think we only need to change sandbox value for old shim. I Will add comment in follow up. Thanks for the suggestion.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 7, 2025
@fuweid fuweid added this pull request to the merge queue Jun 7, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 8, 2025
@fuweid fuweid added this pull request to the merge queue Jun 8, 2025
Merged via the queue into containerd:main with commit eeb9065 Jun 8, 2025
52 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 8, 2025
@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jun 10, 2025

/cherry-pick release/2.1

@fuweid fuweid deleted the fix-11871 branch June 10, 2025 18:27
@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@fuweid: new pull request created: #11971

Details

In response to this:

/cherry-pick release/2.1

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@austinvazquez austinvazquez added cherry-picked/2.1.x PR commits are cherry picked into the release/2.1 branch and removed cherry-pick/2.1.x Change to be cherry picked to release/2.1 branch labels Jun 10, 2025
@fuweid fuweid added cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch and removed cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch labels Jun 11, 2025
smira added a commit to smira/pkgs that referenced this pull request Jun 12, 2025
Drop the hacky patch which was a workaround for gvisor issues.

I tested the fix in 2.1.2:
containerd/containerd#11916 (comment)

Signed-off-by: Andrey Smirnov <[email protected]>
yanghoeg pushed a commit to yanghoeg/pkgs that referenced this pull request May 4, 2026
Drop the hacky patch which was a workaround for gvisor issues.

I tested the fix in 2.1.2:
containerd/containerd#11916 (comment)

Signed-off-by: Andrey Smirnov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch cherry-picked/2.1.x PR commits are cherry picked into the release/2.1 branch ok-to-test size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

gVisor with container 2.1.0

7 participants