Repository navigation
refactor: add internal/concurrency for the bounded errgroup helpers - #14422
Merged
Merged
Conversation
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>
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
dock-tor
approved these changes
Oct 29, 2026
Contributor
There was a problem hiding this comment.
🟢 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
4 of 15 tasks
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
newLimitedErrgroupinpkg/compose, and hand-writtenif max > 0 { eg.SetLimit(max) }variants ininternal/containerops,internal/inspectandinternal/sync. The semaphore-based helpers used to share one budget between concurrent calls (the optional limiter, slot acquire/release, and the limiter-boundedforEach) live inpkg/composetoo.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 importpkg/compose.What the PR brings
One place for the rule, with unchanged behavior:
NewErrgroup,NewLimiter,Acquire,Release,PanicSafeReleaseandForEach, moved as they were and used by their former callers. The package is a leaf with no dependency onpkg/composeorpkg/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