Skip to content
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

fix race condition, waiting for containers when one exit #10725

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions pkg/compose/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,28 @@ func (t *graphTraversal) visit(ctx context.Context, g *Graph) error {
if t.maxConcurrency > 0 {
eg.SetLimit(t.maxConcurrency + 1)
}
nodeCh := make(chan *Vertex)
nodeCh := make(chan *Vertex, expect)
defer close(nodeCh)
// nodeCh need to allow n=expect writers while reader goroutine could have returner after ctx.Done
eg.Go(func() error {
for node := range nodeCh {
expect--
if expect == 0 {
close(nodeCh)
for {
select {
case <-ctx.Done():
return nil
ndeloof marked this conversation as resolved.
Show resolved Hide resolved
case node := <-nodeCh:
expect--
if expect == 0 {
return nil
}
t.run(ctx, g, eg, t.adjacentNodesFn(node), nodeCh)
}
t.run(ctx, g, eg, t.adjacentNodesFn(node), nodeCh)
}
return nil
})

nodes := t.extremityNodesFn(g)
t.run(ctx, g, eg, nodes, nodeCh)

err := eg.Wait()
return err
return eg.Wait()
}

// Note: this could be `graph.walk` or whatever
Expand Down
1 change: 1 addition & 0 deletions pkg/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts
if len(opts.User) > 0 {
service.User = opts.User
}

if len(opts.CapAdd) > 0 {
service.CapAdd = append(service.CapAdd, opts.CapAdd...)
service.CapDrop = utils.Remove(service.CapDrop, opts.CapAdd...)
Expand Down