Skip to content

runtime: invoke Shutdown after every task deletion - #13958

Merged
mxpv merged 1 commit into
containerd:mainfrom
fuweid:should-invoke-shutdown-for-all-containers
Aug 17, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
fuweid:should-invoke-shutdown-for-all-containers

Conversation

@fuweid

@fuweid fuweid commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

TaskService.Shutdown may be invoked multiple times. A grouped shim itself does not terminate while it still has active tasks. It terminates only after receiving a Shutdown request when no active tasks remain.

The shim manager should invoke TaskService.Shutdown after deleting every task, regardless of whether the task represents sandbox or not. This ensures that the shim receives Shutdown when the last active task is deleted.

In CRI, the pause container uses oom_score_adj=-998, making it unlikely to be OOM-killed. However, it may still exit or be killed before the other containers in the sandbox. SandboxService.Shutdown and TaskService.Shutdown are independent APIs. Sandbox service should make sure there is no active containers before shutdown. So, for the task service, we should invoke Shutdown for each task.

Removing the supportSandboxAPIVersion check does not change behavior for shims using task API versions below v3. Those shims were already forced down the non-sandboxed path and received Shutdown after every task deletion. The behavior change applies only to sandboxed tasks using task API v3, which now receive Shutdown after deletion as well.

Part of #8981
REF: #6703

Ensure grouped shims receive shutdown when the last active task is deleted

Copilot AI lite review requested due to automatic review settings August 14, 2026 02:03
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Aug 14, 2026
@fuweid

fuweid commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

cc @mxpv

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR ensures containerd always invokes TaskService.Shutdown after deleting a task (including sandboxed task API v3 cases), so grouped shims reliably receive a shutdown request once the last active task is removed (e.g., when the pause container exits before other sandbox containers).

Changes:

  • Always call waitShutdown() from shimTask.delete() (removing sandbox/API-version conditional behavior).
  • Update task deletion call sites to match the new shimTask.delete signature.
  • Add an integration test covering the “pause exits first” sandbox cleanup scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
integration/issue7496_shutdown_linux_test.go Adds an integration test to validate shim shutdown when the pause task exits before other sandbox containers.
core/runtime/v2/task_manager.go Updates task deletion paths to use the new shimTask.delete signature and removes now-unused sandbox checks.
core/runtime/v2/shim.go Makes shimTask.delete always invoke TaskService.Shutdown via waitShutdown().
core/runtime/v2/shim_load.go Updates leaked-shim cleanup path to use the new shimTask.delete signature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 14, 2026 02:16
@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from 43f173e to 7b17061 Compare August 14, 2026 02:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (1)

integration/issue7496_shutdown_linux_test.go:128

  • The post-RemovePodSandbox assertion is potentially racy/brittle: RemovePodSandbox doesn’t necessarily guarantee the shim has fully exited by the time it returns, so an immediate Connect() can transiently succeed (or fail with a different transport error than the exact string). Consider retrying until Connect fails within a bounded timeout instead of asserting a specific error substring on the first attempt.
	t.Log("Shim should be shutdown")
	_, err = shimCli.Connect(ctx, &apitask.ConnectRequest{})
	require.Error(t, err)
	require.ErrorContains(t, err, "ttrpc: closed")
}

Copilot AI review requested due to automatic review settings August 14, 2026 13:50
@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from 7b17061 to c4694a4 Compare August 14, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 14, 2026 14:21
@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from c4694a4 to 573a260 Compare August 14, 2026 14:21
@kubernetes-prow kubernetes-prow Bot added size/L and removed size/M labels Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (1)

core/runtime/v2/shim.go:581

  • waitShutdown is invoked with the caller context. If the Delete request context is already canceled/expired (a scenario called out in the issue discussion and the FIXME below), timeout.WithContext(ctx, …) will be canceled immediately and the Shutdown RPC won’t be delivered, which can still leave a leaky shim while the task is removed from the manager. Use context.WithoutCancel(ctx) (still bounded by shutdownTimeout) so a best-effort Shutdown is attempted even when the original request context is canceled.
	if err := s.waitShutdown(ctx); err != nil {
		// FIXME(fuweid):
		//
		// If the error is context canceled, should we use context.TODO()
		// to wait for it?
		log.G(ctx).WithField("id", s.ID()).WithError(err).Error("failed to shutdown shim task and the shim might be leaked")

@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from 573a260 to e0f6f0f Compare August 14, 2026 15:14
Copilot AI review requested due to automatic review settings August 14, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@fuweid fuweid moved this from Needs Triage to Needs Reviewers in Pull Request Review Aug 14, 2026
@fuweid fuweid added cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Aug 14, 2026
@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from e0f6f0f to a84e6e4 Compare August 15, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Comment thread docs/sandbox-api.md Resolved
TaskService.Shutdown may be invoked multiple times. A grouped shim
itself does not terminate while it still has active tasks. It terminates only
after receiving a Shutdown request when no active tasks remain.

The shim manager should invoke TaskService.Shutdown after deleting every task,
regardless of whether the task represents sandbox or not. This ensures that the
shim receives Shutdown when the last active task is deleted.

In CRI, the pause container uses oom_score_adj=-998, making it unlikely to be
OOM-killed. However, it may still exit or be killed before the other containers
in the sandbox. SandboxService.Shutdown and TaskService.Shutdown are independent
APIs. Sandbox service should make sure there is no active containers
before shutdown. So, for the task service, we should invoke Shutdown for
each task.

Removing the supportSandboxAPIVersion check does not change behavior for shims
using task API versions below v3. Those shims were already forced down the
non-sandboxed path and received Shutdown after every task deletion. The behavior
change applies only to sandboxed tasks using task API v3, which now receive
Shutdown after deletion as well.

Signed-off-by: Wei Fu <[email protected]>
Copilot AI review requested due to automatic review settings August 17, 2026 22:10
@fuweid
fuweid force-pushed the should-invoke-shutdown-for-all-containers branch from 9bb9ef8 to 402eb31 Compare August 17, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Aug 17, 2026
@mxpv
mxpv added this pull request to the merge queue Aug 17, 2026
Merged via the queue into containerd:main with commit 1b23606 Aug 17, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Aug 17, 2026
@mxpv

mxpv commented Nov 23, 2026

Copy link
Copy Markdown
Member

/cherry-pick 2.3
/cherry-pick 2.0

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: cannot checkout 2.0: error checking out "2.0": exit status 128 fatal: invalid reference: 2.0

Details

In response to this:

/cherry-pick 2.3
/cherry-pick 2.0

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.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: cannot checkout 2.3: error checking out "2.3": exit status 128 fatal: invalid reference: 2.3

Details

In response to this:

/cherry-pick 2.3
/cherry-pick 2.0

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.

@mxpv

mxpv commented Nov 23, 2026

Copy link
Copy Markdown
Member

/cherry-pick release/2.3
/cherry-pick release/2.0

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: #13958 failed to apply on top of branch "release/2.0":

Applying: runtime: invoke Shutdown after every task deletion
Using index info to reconstruct a base tree...
M	core/runtime/v2/shim.go
M	core/runtime/v2/shim_load.go
M	core/runtime/v2/task_manager.go
A	docs/sandbox-api.md
Falling back to patching base and 3-way merge...
Auto-merging core/runtime/v2/shim.go
CONFLICT (content): Merge conflict in core/runtime/v2/shim.go
Auto-merging core/runtime/v2/shim_load.go
CONFLICT (content): Merge conflict in core/runtime/v2/shim_load.go
Auto-merging core/runtime/v2/task_manager.go
CONFLICT (content): Merge conflict in core/runtime/v2/task_manager.go
CONFLICT (modify/delete): docs/sandbox-api.md deleted in HEAD and modified in runtime: invoke Shutdown after every task deletion.  Version runtime: invoke Shutdown after every task deletion of docs/sandbox-api.md left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 runtime: invoke Shutdown after every task deletion

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.0

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.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: new pull request created: #14636

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.0

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.

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

Labels

area/runtime Runtime cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants