mirror of
https://github.com/docker/compose.git
synced 2026-11-19 06:29:52 +00:00
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> |
||
|---|---|---|
| .. | ||
| api | ||
| bridge | ||
| compose | ||
| dryrun | ||
| e2e | ||
| mocks | ||
| remote | ||
| utils | ||
| watch | ||