-
-
Notifications
You must be signed in to change notification settings - Fork 511
Fix: Agent now gracefully handles running containers when killed #6018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
6543
merged 5 commits into
woodpecker-ci:main
from
Pnkcaht:fix/docker-kill-container-on-cancel
Jan 26, 2026
Merged
Fix: Agent now gracefully handles running containers when killed #6018
6543
merged 5 commits into
woodpecker-ci:main
from
Pnkcaht:fix/docker-kill-container-on-cancel
Jan 26, 2026
+22
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6543
reviewed
Jan 26, 2026
6543
reviewed
Jan 26, 2026
6543
approved these changes
Jan 26, 2026
6543
reviewed
Jan 26, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6018 +/- ##
==========================================
- Coverage 21.88% 21.86% -0.02%
==========================================
Files 432 432
Lines 39241 39254 +13
==========================================
- Hits 8586 8581 -5
- Misses 29847 29865 +18
Partials 808 808 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6543
added a commit
to 6543-forks/woodpecker
that referenced
this pull request
Jan 28, 2026
This reverts commit b1cbd96.
Member
|
hotfix removed in #6011 as solved propperly (as per #6018 (comment)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: kill docker container on pipeline cancellation
What was happening
When a pipeline step was canceled (e.g. manual cancel or agent shutdown), the Docker backend would stop waiting for the container but would not actively terminate it.
This caused containers running long-lived commands (like
sleep,tail -f, servers, etc.) to continue running in the background.Related Issue
Closes #6016
What this PR changes
This PR ensures that when the step context is canceled, the running Docker container is immediately killed.
ctx.Done()inWaitStepContainerKillusing a non-cancelable contextWhy this approach
Docker containers do not automatically stop when the caller context is canceled.
Explicitly killing the container on
ctx.Done()guarantees correct cleanup and matches expected CI behavior.Implementation overview
sequenceDiagram participant Engine as Pipeline Engine participant Docker as Docker Backend participant Ctx as Step Context participant C as Container Engine->>Docker: StartStep Docker->>C: docker run Docker->>Docker: WaitStep (ContainerWait) alt Pipeline canceled Ctx-->>Docker: ctx.Done() Docker->>C: ContainerKill (SIGKILL) Docker->>Docker: ContainerWait returns else Step finishes normally C-->>Docker: container exits end Docker-->>Engine: Step state (exit code)How it was tested
Test pipeline configuration
To reproduce the issue and validate the fix, a minimal Woodpecker pipeline was used with
skip_clone: trueand a long-running step.Terminal Output
The behavior was validated using a long-running Docker container to simulate a pipeline step that does not exit on its own.
Before the fix
After the fix
Example manual verification: