Repository navigation
feat(up): stream the logs while --wait waits for the services - #14454
Conversation
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
| // then ends the session leaving them up. The caller's ctx, not | ||
| // globalCtx: the monitor cancels the latter once every container is | ||
| // gone, which must not abort the verification of one-shot services. | ||
| err = s.awaitProjectReady(ctx, project, options.Start.WaitTimeout) |
There was a problem hiding this comment.
[low] awaitProjectReady uses the outer ctx instead of globalCtx, so a Ctrl+C signal cannot immediately cancel health-check polling
When --wait is active and the user presses Ctrl+C, runEventLoop calls gracefulTeardown() → stopApplication(), which begins stopping containers. However, the context passed to awaitProjectReady is the outer ctx (never cancelled by the signal), not globalCtx. The polling loop in waitDependencies runs on a 500 ms tick and returns only when it detects a failed/stopped container or ctx.Done() fires.
The code comment on the awaitProjectReady call documents the tradeoff: globalCtx is cancelled by the monitor once all containers are gone, which would prematurely abort readiness verification for one-shot services before they complete. That explains the choice of ctx. The practical impact is a brief delay (at most one poll cycle, ~500 ms) before awaitProjectReady exits after containers stop — not an indefinite hang.
Consider whether the signal-responsiveness gap warrants a dedicated cancel signal (e.g. a context derived from both ctx and the signal channel), so that the CLI can exit faster on Ctrl+C without breaking the one-shot-service guarantee. The tradeoff is intentional and documented, so this is a minor nit.
| Confidence | Score |
|---|---|
| 🟡 moderate | 62/100 |
There was a problem hiding this comment.
Intentional, see the comment above the call: the monitor cancels globalCtx once every container is gone, which would abort the readiness check of one-shot services before they are verified.
On Ctrl+C/SIGTERM the stack is stopped by gracefulTeardown, the poll sees the stopped containers on its next tick (≤ 500 ms) and returns; the error is dropped because isTerminated is set. No change.
9f62263 to
bc93cfb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
| // then ends the session leaving them up. The caller's ctx, not | ||
| // globalCtx: the monitor cancels the latter once every container is | ||
| // gone, which must not abort the verification of one-shot services. | ||
| err = s.awaitProjectReady(ctx, project, options.Start.WaitTimeout) |
There was a problem hiding this comment.
[medium] awaitProjectReady failure silently drops goroutine-collected errors
When --wait is active and awaitProjectReady returns an error (e.g. a service never becomes healthy), the code falls into the pre-existing early-return path:
if err != nil && !u.isTerminated.Load() {
cancel()
_ = u.eg.Wait()
return err // u.errs is NOT joined here
}u.errs — populated by background goroutines via appendErr (e.g. container lifecycle events, log-streaming errors) — is never joined before returning. The caller only sees the awaitProjectReady error; any supplementary diagnostic errors from the goroutines are silently discarded.
The success path (and all non-error paths) correctly does:
_ = u.eg.Wait()
err = errors.Join(u.errs...)Suggested fix — in the early-return branch, join u.errs before returning so the caller gets the full picture:
if err != nil && !u.isTerminated.Load() {
cancel()
_ = u.eg.Wait()
return errors.Join(append(u.errs, err)...)
}| Confidence | Score |
|---|---|
| 🟡 moderate | 60/100 |
There was a problem hiding this comment.
Not changing this here. The err != nil && !isTerminated early return is pre-existing on main and untouched by this PR; it applies the same way to runStart errors. Joining u.errs there would change the error reporting of every up, not only --wait, so it belongs in a separate change.
For the --wait case, awaitProjectReady's error is the relevant one (the unhealthy/exited service) and its logs have already been streamed. What u.errs could add after cancel() is mostly context.Canceled, which appendErr already filters. The suggested snippet also reads u.errs without u.mu.
There was a problem hiding this comment.
Thank you for the clarification — you're absolutely right that this early-return path is pre-existing and shared by both runStart and awaitProjectReady, so changing error handling there would indeed be a separate, broader decision affecting all up invocations.
Good catches on the context.Canceled filtering and the missing mutex protection. I should have traced through appendErr more carefully; if it's already discarding context cancellation errors, then u.errs after cancel() is likely either empty or contains only unrelated events that don't add diagnostic value for the wait-timeout case.
I'll withdraw the suggestion for this PR. If there's ever a case where goroutine errors before the cancel do provide useful context, that would be a separate discussion for the shared early-return path.
bc93cfb to
a08506b
Compare
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
a08506b to
9861086
Compare
ndeloof
left a comment
There was a problem hiding this comment.
One thing to fix before merging: Ctrl+C during --wait can leave the stack running (see inline).
nit: no unit test covers the Wait path of runInteractiveUp (success then cancel(), failure, interruption), which is how the above went unnoticed. The new dry-run test also discards the error of Up (_ = h.svc.Up(...)).
Without --detach, `up --wait` now attaches to the containers and streams their logs until the services are running|healthy, then ends the session and leaves them up. Until now --wait silently forced --detach, so a service failing to become healthy left no clue about why. --detach --wait keeps the previous silent behavior, and --dry-run stays on the detached plan. The library Validate accepts Wait with Attach, and still rejects OnExit, ExitCodeFrom and Watch with it. The navigation menu is disabled while waiting. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Once every attached container is gone the monitor ends the session, and with it the event loop that handles Ctrl+C: later interruptions are lost. During --wait that left the stack running on exit 130: end the wait without canceling, and stop the stack from there when the loop is gone. During the start phase, blocked on dependencies of unattached services, the signal was swallowed and the command hung: keep the session open. Add tests for both and document that --wait leaves the services up. Keep an api test valid now that Wait is accepted together with Attach. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
9861086 to
a2fd72a
Compare
docker-agent
left a comment
There was a problem hiding this comment.
Fixes #9122
docker compose up --waitused to force--detach, so a service that never became healthy left no output explaining why. Without--detach,--waitnow attaches to the containers and streams their logs until the services are running|healthy. It then ends the session and leaves the containers up.up --detach --waitis unchanged and stays silent.--dry-run up --waitstays on the detached plan.--waitis still rejected with--watch,--abort-on-container-exit,--abort-on-container-failure,--exit-code-fromand--attach.UpOptions.Validatenow acceptsWaitwithAttachand still rejectsOnExit,ExitCodeFromandWatchwith it.Behavior change: Ctrl+C or SIGTERM during
up --waitnow stops the stack and exits 130. Before, only the CLI was killed and the containers were left running.🤖 Generated with Claude Code