Repository navigation
fix(hooks): stop or restart a container whose pre_stop hook cannot run - #14547
Merged
Merged
Conversation
Signed-off-by: Hiroto Toyoda <hirototoyoda20020927@gmail.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the pre-stop hook handling changes.
No open issues 🎉
What changed in this PR
Fixes #14545 by allowing Compose to continue stopping or restarting a container when its pre_stop hooks cannot run because the container is stopped or paused.
Changes:
- Centralizes pre-stop hook handling, skipping conflicts while preserving relay-container exclusions and other error handling.
- Updates stop and restart to use the shared helper.
- Adds unit and end-to-end regression coverage for stopped, paused, and removed containers.
| File | Description |
|---|---|
pkg/compose/restart.go |
Uses the shared helper so hook conflicts no longer abort restart. |
pkg/compose/restart_test.go |
Tests restarting a stopped container after a hook conflict. |
pkg/compose/hook.go |
Adds shared pre-stop hook handling for conflicts and missing containers. |
pkg/compose/down.go |
Continues stopping after hook conflicts while skipping removed containers. |
pkg/compose/down_test.go |
Tests hook conflicts during stop and handling of removed containers. |
internal/e2e/testdata/TestPreStopHookStopPaused/compose.yaml |
Adds a hooked service fixture for paused-container coverage. |
internal/e2e/testdata/TestPreStopHookRestartAfterStop/compose.yaml |
Adds a hooked service fixture for restart-after-stop coverage. |
internal/e2e/hooks_test.go |
Adds scenarios verifying restart after stop and stopping paused containers. |
Review effort: Balanced
ndeloof
approved these changes
Nov 24, 2026
ndeloof
enabled auto-merge (rebase)
November 24, 2026 14:14
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3 tasks
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
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.
What this PR does
Compose runs
pre_stophooks as execs in the container, and a stopped or paused container rejects the exec with a conflict. Because of that,restartfailed on a stopped or crashed service that haspre_stophooks and left it stopped.stopon such a service while it was paused exited 0 but left the container paused.With this change, a conflict skips the hooks, since there is no process to run them in, and the stop or restart goes on.
Related issue
Fixes #14545
Changes made
pkg/compose/hook.go: addrunPreStopHooks, shared bystopandrestart. It skips relay containers, as both call sites did before.pkg/compose/down.go:stopContaineruses the helper. A conflict no longer returns beforeContainerStop, so a paused container is stopped. A container that is already gone is still not stopped, as before.pkg/compose/restart.go:restartContaineruses the helper, so a conflict no longer aborts the restart.Testing done
make testmake e2e-composeormake e2e-compose-standalonemake lintmake fmtAI tool used (if applicable)
AI Tool:
Additional context
(not mandatory) A picture of a cute animal, if possible in relation to what you did