-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix: honor --parallel across all bulk engine-call fan-outs #14177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glours
wants to merge
4
commits into
docker:main
Choose a base branch
from
glours:fix/parallel-limit-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ccf0525
fix: honor --parallel across all bulk engine-call fan-outs
glours 7142ce8
fix: stop --parallel starving log-follow's monitor or restart's cap
glours 57d2e19
fix: close remaining --parallel gaps on down/stop/start
glours 67a76a8
fix: bound compose cp's fan-out and panic-safe log slot release
glours File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| Copyright 2026 Docker Compose CLI authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package compose | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| // TestNewLimitedErrgroup_NonPositiveIsUnlimited guards against the bug this | ||
| // helper exists to fix: errgroup.SetLimit(0) means "allow zero goroutines", | ||
| // not "unlimited". A composeService{} built without going through | ||
| // NewComposeService has maxConcurrency's Go zero-value (0), so an | ||
| // unconditional SetLimit(maxConcurrency) at any call site would silently | ||
| // hang forever instead of running. | ||
| func TestNewLimitedErrgroup_NonPositiveIsUnlimited(t *testing.T) { | ||
| for _, maxConcurrency := range []int{0, -1} { | ||
| t.Run(fmt.Sprintf("maxConcurrency=%d", maxConcurrency), func(t *testing.T) { | ||
| eg, _ := newLimitedErrgroup(t.Context(), maxConcurrency) | ||
|
|
||
| done := make(chan struct{}) | ||
| go func() { | ||
| for range 5 { | ||
| eg.Go(func() error { return nil }) | ||
| } | ||
| close(done) | ||
| }() | ||
|
|
||
| select { | ||
| case <-done: | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("eg.Go blocked: maxConcurrency <= 0 must mean unlimited, not SetLimit(0) (zero goroutines allowed)") | ||
| } | ||
| assert.NilError(t, eg.Wait()) | ||
| }) | ||
| } | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| Copyright 2020 Docker Compose CLI authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package compose | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/moby/moby/api/types/container" | ||
| "github.com/moby/moby/client" | ||
| "go.uber.org/mock/gomock" | ||
| "gotest.tools/v3/assert" | ||
|
|
||
| compose "github.com/docker/compose/v5/pkg/api" | ||
| ) | ||
|
|
||
| // TestCopyToService_ConcurrencyIsBoundedAcrossContainers guards against the | ||
| // same unbounded-fan-out bug fixed everywhere else in this package: `compose | ||
| // cp` copying to a service fans out one goroutine per matched container via | ||
| // a bare errgroup.Group, ignoring --parallel entirely. | ||
| func TestCopyToService_ConcurrencyIsBoundedAcrossContainers(t *testing.T) { | ||
| svc, apiClient := newTestService(t, WithMaxConcurrency(1)) | ||
|
|
||
| srcFile := filepath.Join(t.TempDir(), "src.txt") | ||
| assert.NilError(t, os.WriteFile(srcFile, []byte("hello"), 0o644)) | ||
|
|
||
| const numContainers = 4 | ||
| var containers []container.Summary | ||
| for i := range numContainers { | ||
| containers = append(containers, testContainer("myservice", string(rune('a'+i)), false)) | ||
| } | ||
|
|
||
| apiClient.EXPECT().ContainerList(gomock.Any(), gomock.Any()). | ||
| Return(client.ContainerListResult{Items: containers}, nil) | ||
|
|
||
| apiClient.EXPECT().ContainerStatPath(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(client.ContainerStatPathResult{Stat: container.PathStat{Mode: os.ModeDir}}, nil). | ||
| Times(numContainers) | ||
|
|
||
| tracker := &peakConcurrencyTracker{} | ||
| apiClient.EXPECT().CopyToContainer(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| DoAndReturn(func(_ context.Context, _ string, opts client.CopyToContainerOptions) (client.CopyToContainerResult, error) { | ||
| tracker.enter() | ||
| time.Sleep(20 * time.Millisecond) // widen the window for a concurrency violation to show up | ||
| tracker.leave() | ||
| _, err := io.Copy(io.Discard, opts.Content) | ||
| return client.CopyToContainerResult{}, err | ||
| }). | ||
| Times(numContainers) | ||
|
|
||
| err := svc.copy(t.Context(), "prj", compose.CopyOptions{ | ||
| Source: srcFile, | ||
| Destination: "myservice:/dest", | ||
| }) | ||
| assert.NilError(t, err) | ||
| assert.Equal(t, tracker.Peak(), 1, "cp must never run more than maxConcurrency CopyToContainer calls at once") | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: this is the only remaining direct
eg.SetLimit(t.maxConcurrency + 1)(line ~146) not routed through the newnewLimitedErrgrouphelper. It was already correctly guarded (if t.maxConcurrency > 0) before this PR, so not a bug -- just an inconsistency now that every other call site shares one helper. Could fold intonewLimitedErrgrouptoo (with the+1applied by the caller) for a single source of truth.