fix race condition, waiting for containers when one exit

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2023-06-20 09:03:55 +02:00 committed by Nicolas De loof
parent 401334e03f
commit a2ce602f6c
2 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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...)