Skip to content

feat(up): stream the logs while --wait waits for the services - #14454

Merged
glours merged 2 commits into
docker:mainfrom
glours:up-wait-stream-logs
Nov 17, 2026
Merged

glours merged 2 commits into
docker:mainfrom
glours:up-wait-stream-logs

Conversation

@glours

@glours glours commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9122

docker compose up --wait used to force --detach, so a service that never became healthy left no output explaining why. Without --detach, --wait now 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 --wait is unchanged and stays silent.
  • --dry-run up --wait stays on the detached plan.
  • The navigation menu is disabled while waiting.
  • --wait is still rejected with --watch, --abort-on-container-exit, --abort-on-container-failure, --exit-code-from and --attach. UpOptions.Validate now accepts Wait with Attach and still rejects OnExit, ExitCodeFrom and Watch with it.

Behavior change: Ctrl+C or SIGTERM during up --wait now stops the stack and exits 130. Before, only the CLI was killed and the containers were left running.

🤖 Generated with Claude Code

@glours
glours requested review from a team as code owners November 4, 2026 13:07
@glours
glours requested a review from ndeloof November 4, 2026 13:07

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

Comment thread pkg/compose/up.go Outdated
// 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)

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.

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@glours
glours force-pushed the up-wait-stream-logs branch from 9f62263 to bc93cfb Compare November 4, 2026 16:17
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@glours
glours requested a review from docker-agent November 4, 2026 16:31

@docker-agent docker-agent 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.

Assessment: 🟡 NEEDS ATTENTION

Comment thread pkg/compose/up.go Outdated
// 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)

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.

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

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.

@glours
glours force-pushed the up-wait-stream-logs branch from bc93cfb to a08506b Compare November 13, 2026 16:34
@glours
glours requested a review from docker-agent November 13, 2026 16:35

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

@glours
glours force-pushed the up-wait-stream-logs branch from a08506b to 9861086 Compare November 16, 2026 14:41

@ndeloof ndeloof 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.

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(...)).

Comment thread pkg/compose/up.go Resolved
Comment thread pkg/compose/up.go Resolved
glours and others added 2 commits November 16, 2026 17:08
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>
@glours
glours force-pushed the up-wait-stream-logs branch from 9861086 to a2fd72a Compare November 16, 2026 17:32
@glours
glours requested a review from docker-agent November 16, 2026 17:56

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

@glours
glours merged commit ed25575 into docker:main Nov 17, 2026
65 checks passed
@glours
glours deleted the up-wait-stream-logs branch November 17, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream logs during --wait

3 participants