Skip to content

shim-runc-v2: record exit status in bundle - #14113

Merged
fuweid merged 1 commit into
containerd:mainfrom
fuweid:cache-exit-code-in-state-dir
Sep 10, 2026
Merged

fuweid merged 1 commit into
containerd:mainfrom
fuweid:cache-exit-code-in-state-dir

Conversation

@fuweid

@fuweid fuweid commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

The task plugin may send duplicate task events to a subscriber. The second event is generated by the shim delete command and currently it doesn't know when container exited and what its exit code is. So, it always returns 137 as exit code. It may leave subscribers unsure which event they should trust (see #6429).

This patch stores exit status into bundle state dir. The bundle state dir is recommended to be tmpfs. Ideally, the write syscall won't take too long.

Follow-up: #14020

Avoid inaccurate duplicate task exit events from shim delete by recording exit status in bundle

Copilot AI lite review requested due to automatic review settings September 4, 2026 21:55
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Sep 4, 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.

🟢 Approval recommended

The behavioral change is well-scoped, exercised by new unit/integration tests, and only a minor log-message wording nit was found.

Pull request overview

This PR fixes incorrect/ambiguous duplicate task exit/delete events when a shim is cleaned up via the shim delete path by persisting the actual runc.Exit (pid/status/timestamp) into the bundle state directory and reusing it during forced cleanup.

Changes:

  • Record init-process exit status/time into exitstatus.json in the bundle (shim side) when the init exits.
  • Teach shim-delete cleanup to prefer the recorded exit status (falling back to SIGKILL semantics when unavailable).
  • Add/extend integration tests to assert correct exit/delete event contents (including multi-container shared-shim cases), vendoring protocmp/cmpopts to make protobuf comparisons robust.
File summaries
File Description
cmd/containerd-shim-runc-v2/task/service.go Persist init exit status/timestamp into the bundle on init exit.
cmd/containerd-shim-runc-v2/runc/util.go Add atomic write/read helpers for exitstatus.json in the bundle dir.
cmd/containerd-shim-runc-v2/runc/util_test.go Unit tests for exitstatus read/write validation and corruption handling.
cmd/containerd-shim-runc-v2/manager/manager_linux.go Prefer recorded exit status during forced cleanup (shim-delete path), with fallback behavior retained.
integration/release_upgrade_linux_test.go Refactor shim bundle client builder to support non-k8s.io namespaces.
integration/release_upgrade_exit_status_linux_test.go Add upgrade regression test coverage around shim exit-status handling.
integration/issue7496_shutdown_linux_test.go Strengthen event assertions (exit/delete payloads) and add multi-container shared-shim exit-status preservation coverage.
vendor/modules.txt Update vendored module package list for newly required packages.
vendor/google.golang.org/protobuf/testing/protocmp/xform.go Vendored protocmp support (protobuf-aware cmp transforms).
vendor/google.golang.org/protobuf/testing/protocmp/util.go Vendored protocmp utility options (ignore/sort/filter).
vendor/google.golang.org/protobuf/testing/protocmp/reflect.go Vendored protocmp reflective message/list/map adapters.
vendor/google.golang.org/protobuf/internal/msgfmt/format.go Vendored protobuf message formatter used by protocmp.
vendor/github.com/google/go-cmp/cmp/cmpopts/xform.go Vendored cmpopts helpers used by protocmp/tests.
vendor/github.com/google/go-cmp/cmp/cmpopts/struct_filter.go Vendored cmpopts struct filtering utilities.
vendor/github.com/google/go-cmp/cmp/cmpopts/sort.go Vendored cmpopts sorting transformers.
vendor/github.com/google/go-cmp/cmp/cmpopts/ignore.go Vendored cmpopts ignore options.
vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go Vendored cmpopts equate/comparer helpers.
Review details
  • Files reviewed: 7/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 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 September 4, 2026 22:23
@fuweid
fuweid force-pushed the cache-exit-code-in-state-dir branch from 2d80347 to 0a95d5b Compare September 4, 2026 22:23
@fuweid fuweid added this to the 2.4 milestone Sep 4, 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.

🟡 Changes recommended

Exit status persistence is currently coupled to delayed init-exit publication, leaving a window where a shim can terminate before writing exitstatus.json, reintroducing the incorrect fallback status.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 7/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

The task plugin may send duplicate task events to a subscriber. The second
event is generated by the shim delete command and currently it doesn't know
when container exited and what its exit code is. So, it always returns 137
as exit code. It may leave subscribers unsure which event they should trust
(see containerd#6429).

This patch stores exit status into bundle state dir. The bundle state dir
is recommended to be tmpfs. Ideally, the write syscall won't take too long.

Signed-off-by: Wei Fu <[email protected]>
@fuweid
fuweid force-pushed the cache-exit-code-in-state-dir branch from 0a95d5b to 3264a09 Compare September 8, 2026 11:57
Copilot AI review requested due to automatic review settings September 8, 2026 11:57

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.

🟡 Changes recommended

The new exit-status recording currently overwrites the exit timestamp with a time.Now()-derived value, which can make the persisted exit metadata inaccurate and should be corrected before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 7/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

@dmcgowan dmcgowan moved this from Needs Triage to Review In Progress in Pull Request Review Sep 9, 2026
@fuweid

fuweid commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@AkihiroSuda could you please take a look on this? thanks

@AkihiroSuda
AkihiroSuda added this pull request to the merge queue Sep 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 10, 2026
@fuweid
fuweid added this pull request to the merge queue Sep 10, 2026
Merged via the queue into containerd:main with commit 51e8aef Sep 10, 2026
95 of 98 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants