Skip to content

Commit

Permalink
fix race condition, waiting for containers when one exit
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jun 20, 2023
1 parent 401334e commit a2ce602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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
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

0 comments on commit a2ce602

Please sign in to comment.