Skip to content

refactor: add internal/concurrency for the bounded errgroup helpers - #14422

Merged
ndeloof merged 1 commit into
docker:mainfrom
ndeloof:internal-concurrency
Oct 29, 2026
Merged

ndeloof merged 1 commit into
docker:mainfrom
ndeloof:internal-concurrency

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Part of #14396

What this PR does, in one sentence

Gathers the "run at most N things at once, where N <= 0 means unlimited" helpers into a single leaf package, internal/concurrency, instead of copying them in every package that needs them.

Context

The same bounded-errgroup helper currently exists in several places: newLimitedErrgroup in pkg/compose, and hand-written if max > 0 { eg.SetLimit(max) } variants in internal/containerops, internal/inspect and internal/sync. The semaphore-based helpers used to share one budget between concurrent calls (the optional limiter, slot acquire/release, and the limiter-bounded forEach) live in pkg/compose too.

Each copy exists for the same reason: errgroup.SetLimit(0) means "allow zero goroutines", not "unlimited", so a maxConcurrency left at its Go zero value would hang a command forever unless every call site remembers the guard. The extractions in progress under #14396 each carry another copy of these helpers, since the packages they create cannot import pkg/compose.

What the PR brings

One place for the rule, with unchanged behavior: NewErrgroup, NewLimiter, Acquire, Release, PanicSafeRelease and ForEach, moved as they were and used by their former callers. The package is a leaf with no dependency on pkg/compose or pkg/api, so any package can import it without a cycle.

The semantics (<= 0 is unlimited, the bound is never exceeded, a shared limiter caps the combined concurrency of several calls, the first error cancels the others) are covered by deterministic unit tests that rely on channels and atomic counters only, not on sleeps or timeouts.

Why this is the right next brick

The remaining extractions of #14396 can import this package rather than duplicate the helpers once more, and the existing copies disappear as they are rebased onto it.

🤖 Generated with Claude Code

The "errgroup bounded to maxConcurrency, where <= 0 means unlimited" helper was copied in several places (pkg/compose, internal/containerops, internal/inspect, internal/sync), together with the semaphore-based slot helpers used to share one budget across concurrent calls. Gather them in a leaf package so the extractions in progress can import it instead of duplicating it again. Behavior is unchanged.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested review from a team as code owners October 29, 2026 09:03

@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

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/compose/down.go 75.00% 0 Missing and 2 partials ⚠️
pkg/compose/logs.go 71.42% 1 Missing and 1 partial ⚠️
pkg/compose/executor.go 66.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@ndeloof
ndeloof merged commit 80e4a0a into docker:main Oct 29, 2026
64 of 65 checks passed
@ndeloof
ndeloof deleted the internal-concurrency branch October 29, 2026 09:19

Copilot AI 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.

🟢 Approval recommended

The shared concurrency-helper extraction has no active review issues.

No open issues 🎉

What changed in this PR

Extracts Compose’s shared concurrency helpers into the leaf package internal/concurrency, supporting the package separation in #14396 without changing concurrency behavior or adding public API.

Changes:

  • Centralizes bounded errgroups and shared semaphore helpers, preserving “zero or negative means unlimited.”
  • Migrates existing callers and removes duplicate helper implementations.
  • Adds channel- and atomic-based unit tests for limits, cancellation, shared budgets, and panic-safe release.
File Description
pkg/​compose/​watch.go Uses the shared errgroup helper for watch execution.
pkg/​compose/​up.go Uses the shared limiter for opening log streams.
pkg/​compose/​up_test.go Updates the log concurrency test to use the extracted limiter.
pkg/​compose/​stop.go Uses the shared limiter across services.
pkg/​compose/​restart.go Uses shared limiter and iteration helpers for restarts.
pkg/​compose/​remove.go Uses the shared errgroup helper for removal.
pkg/​compose/​relay.go Uses shared slot acquisition and release helpers.
pkg/​compose/​push.go Uses the shared errgroup helper for image pushes.
pkg/​compose/​pull.go Uses the shared errgroup helper for image pulls.
pkg/​compose/​model.go Uses the shared errgroup helper for model setup.
pkg/​compose/​logs.go Migrates log concurrency and panic-safe slot handling.
pkg/​compose/​logs_test.go Updates helper names in comments only.
pkg/​compose/​images.go Uses shared errgroups for image inspection.
pkg/​compose/​image_pruner.go Uses shared limiter and iteration helpers for pruning.
pkg/​compose/​executor.go Uses shared helpers for plan execution slots.
pkg/​compose/​down.go Migrates teardown operations to shared concurrency helpers.
pkg/​compose/​down_test.go Uses the extracted limiter in image-removal coverage.
pkg/​compose/​dependencies.go Uses the shared errgroup helper for graph traversal.
pkg/​compose/​containers.go Uses the shared errgroup helper for container iteration.
pkg/​compose/​compose.go Removes the extracted concurrency implementations.
pkg/​compose/​compose_test.go Removes the unlimited-concurrency test replaced in the new package.
internal/​sync/​tar.go Uses the shared errgroup while retaining error collection.
internal/​inspect/​top.go Uses the shared errgroup for process inspection.
internal/​inspect/​ps.go Uses the shared errgroup for container inspection.
internal/​inspect/​inspect.go Removes the duplicate bounded errgroup helper.
internal/​containerops/​containerops.go Replaces inline errgroup limit setup with the shared helper.
internal/​concurrency/​concurrency.go Defines the extracted errgroup, limiter, and iteration helpers.
internal/​concurrency/​concurrency_test.go Tests concurrency bounds, cancellation, and slot release behavior.

Review effort: Balanced

@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

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.

4 participants