fix(container): set Detach true in ExecStart to prevent blocking on command execution - #1683
Conversation
…ommand execution - Add `Detach: true` to `ExecStartOptions` so the daemon does not block until the command finishes - Update test mock handler to verify `Detach: true` is sent in the `ExecStart` request - Add explicit test case documenting the `Detach: true` requirement for `ExecStart`
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughExecuteCommand is updated to start Docker exec instances with ChangesDetach Flag in Exec Start
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 5 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1683 +/- ##
==========================================
+ Coverage 74.60% 74.80% +0.20%
==========================================
Files 59 59
Lines 9839 9948 +109
==========================================
+ Hits 7340 7442 +102
- Misses 2237 2241 +4
- Partials 262 265 +3
🚀 New features to boost your workflow:
|
This PR fixes ExecStart blocking lifecycle hooks by setting Detach: true and preventing false exit code 126 on Docker Engine v29+.
Problem
Under Docker Engine v29 (moby/moby v29+),
ExecStartwithDetach=false(the default) blocks synchronously until the command finishes. When watchtower subsequently callsExecAttachto capture output, the exec instance is already complete, and the daemon responds with "exec command is already running". This error text gets captured as the command output, andExecInspectreports exit code 126, causing the lifecycle hook to be marked as failed despite the command having actually succeeded. Every container with a pre-update lifecycle hook fails its update.Solution
Set
Detach: trueinExecStartOptionsso thatExecStartreturns immediately after launching the command in the background. The subsequentExecAttachcan then properly stream output while the command runs, andwaitForExecOrTimeoutcorrectly retrieves the exit code viaExecInspect. This matches the standard Docker API pattern for non-blocking exec with output capture.Changes
pkg/container/client.go:1025— AddedDetach: truetoExecStartOptionsso ExecStart does not block until command completionpkg/container/client_test.go— Added test verifyingExecStartsendsDetach: trueand updated mock to expect itSummary by CodeRabbit
Bug Fixes