compose/pkg
Nicolas De Loof 382383d0c5 fix(executor): make phase cancellation race-free end to end
Three related findings from Copilot and docker-agent on the
phase-scoped cancellation commit, all stemming from the same root
cause: switching run() from errgroup.WithContext's own atomic
cancel-with-error-record to an explicit, separate cancelPhase() call
reopened timing windows that errgroup.WithContext used to close for
free.

- Copilot (high): cancelPhase() unblocks every sibling in that phase
  before this goroutine's own error reaches errgroup.Group's internal
  errOnce -- a sibling woken by the cancellation can return a bare
  context.Canceled of its own and win that race, hiding the actual
  daemon error or DeadlineExceeded (and making upDetached's own
  DeadlineExceeded translation unreliable with it).
- docker-agent (medium): the "is this my own genuine failure"
  nodeCtx.Err() == nil check and the cancellation it gates aren't
  atomic -- two genuinely concurrent same-phase failures can both pass
  it before either's cancelPhase() takes effect, both emitting a group
  Error event for the same resource.
- docker-agent (medium): the dependency-wait loop's early return on
  ctx cancellation skipped close(rs.done[node.ID]), the only exit path
  that did. Not reachable today (every dependent in the same phase
  shares that phase's ctx, already canceled by the time it would
  matter), but latent: nothing in runNode enforces that no future
  cross-phase dependency edge ever relies on this channel closing.

All three close around one new type, phaseCancel, bundling a phase's
context/cancel pair with a sync.Once: the first node in a phase to
fail records its error and emits the group event inside that Once,
cancels the phase's context, and every later caller -- genuine
concurrent failure or cancellation casualty alike -- is a silent
no-op. run() returns a phase's recorded error over whatever
eg.Wait() itself picked, so errgroup's own race can no longer surface
a cancellation casualty's error in its place. The done-channel close
moved to a single `defer` at the top of runNode, covering every exit
path uniformly instead of three separate explicit calls.

TestExecutePlanConcurrentPhaseFailureKeepsOriginatingError exercises
the first scenario under real concurrency (one immediately-failing
node alongside many siblings a dependency-wait unblocks via its
cancellation) -- see its own comment for why this specific race can't
be forced to fail by ablation in an in-process test (the Go scheduler
never actually lets a sibling win it here), so the fix's correctness
rests on reading errgroup's own errOnce.Do source directly, confirmed
independently by two reviewers, not on this test alone.

Verified: go test -race -count=10 ./pkg/compose/... clean; full e2e
suite re-run clean against a locally built binary (same 3
pre-existing, environment-specific failures as the stack's baseline).

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
..
api feat(push): add --ignore-missing to skip images not available locally 2026-10-14 21:34:38 +02:00
bridge build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
compose fix(executor): make phase cancellation race-free end to end 2026-10-15 14:52:20 +02:00
dryrun feat(registry): use the Docker Desktop Hub session for Docker Hub credentials 2026-10-07 14:24:28 +02:00
e2e feat(run): --no-recreate reuses existing dependencies as-is 2026-10-14 09:34:19 +02:00
mocks refactor(api): regenerate mocks for the split Compose interfaces 2026-10-12 12:03:29 +02:00
remote docs(registry): trim comments 2026-10-07 14:24:28 +02:00
utils fix: make e2e tests pass reliably locally with Docker Desktop 2026-05-18 10:55:41 +02:00
watch golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00