Skip to content

cri: don't leak task when StartContainer cleanup fails to delete task - #14218

Merged
mxpv merged 1 commit into
containerd:mainfrom
mxpv:leak
Sep 24, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
mxpv:leak

Conversation

@mxpv

@mxpv mxpv commented Sep 23, 2026

Copy link
Copy Markdown
Member

When StartContainer fails after the task is created and the cleanup task delete fails (e.g. it timed out on a stuck shim), the container was recorded as EXITED while its task could potentially remained.

RemoveContainer only reaps tasks for RUNNING and UNKNOWN containers, so every kubelet GC retry failed with "cannot delete running task" and the container was never collected.

Record the container as UNKNOWN when task cleanup cannot be confirmed so RemoveContainer force-stops it and retries the cleanup.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Sep 23, 2026
Copilot AI lite review requested due to automatic review settings September 23, 2026 23:36
@mxpv mxpv added kind/resource-leak Issues involving leaked processes, goroutines, file descriptors, mounts or other resources. cherry-pick/2.4.x Change to be cherry picked to release/2.4 labels Sep 23, 2026
@mxpv
mxpv requested a review from samuelkarp September 23, 2026 23:39

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.

Copilot review overview

🟡 Changes recommended

The UNKNOWN state is not persisted, so restart recovery can still leave tasks leaked.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Updates CRI start-failure cleanup so containers with unconfirmed task deletion remain recoverable for later cleanup retries.

Changes:

  • Track task deletion failures during StartContainer cleanup.
  • Record affected containers as UNKNOWN.
  • Add test coverage and configurable test client services.
File Description
internal/​cri/​server/​container_stats_stream_test.go Extends test client configuration.
internal/​cri/​server/​container_start.go Records unknown state when task deletion fails.
internal/​cri/​server/​container_start_test.go Tests cleanup failure state transitions.

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

Comment thread internal/cri/server/container_start.go Resolved

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.

Copilot review overview

🟡 Changes recommended

Handle ErrNotFound as unconfirmed cleanup and initialize NRI in the regression test.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 23, 2026 23:55

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.

Copilot review overview

🟡 Changes recommended

Restart recovery does not handle an EXITED container with a still-running task, potentially leaving cleanup unreachable.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)

Comment thread internal/cri/server/container_start.go Resolved
Comment thread internal/cri/server/container_start.go Resolved
When StartContainer fails after the task is created and the cleanup
task delete fails (e.g. it timed out on a stuck shim), the container
was still recorded as EXITED while its task remained. RemoveContainer
only reaps tasks for RUNNING and UNKNOWN containers, so every kubelet
GC retry failed with "cannot delete running task" and the container
was never collected. Record the container as UNKNOWN when task cleanup
cannot be confirmed so RemoveContainer force-stops it and retries the
cleanup, keeping the StartError reason in both cases.

Signed-off-by: Maksym Pavlenko <[email protected]>
Copilot AI review requested due to automatic review settings September 24, 2026 16:55

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.

Copilot review overview

🔵 Needs a closer look

ErrNotFound cleanup failures can still leave task records unreaped.

Review effort: Lite
Findings: None

Resolved since last review (2)

@mikebrow mikebrow left a comment

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.

LGTM

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Sep 24, 2026
@mxpv
mxpv added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@mxpv
mxpv added this pull request to the merge queue Sep 24, 2026
Merged via the queue into containerd:main with commit b450304 Sep 24, 2026
98 of 106 checks passed
@mxpv

mxpv commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.4

@mxpv
mxpv deleted the leak branch September 24, 2026 19:45
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: new pull request created: #14223

Details

In response to this:

/cherry-pick release/2.4

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

cherry-pick/2.4.x Change to be cherry picked to release/2.4 kind/resource-leak Issues involving leaked processes, goroutines, file descriptors, mounts or other resources. size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants