mirror of
https://github.com/docker/compose.git
synced 2025-07-17 18:54:29 +02:00
fix race condition, waiting for containers when one exit
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
401334e03f
commit
a2ce602f6c
@ -140,24 +140,28 @@ func (t *graphTraversal) visit(ctx context.Context, g *Graph) error {
|
|||||||
if t.maxConcurrency > 0 {
|
if t.maxConcurrency > 0 {
|
||||||
eg.SetLimit(t.maxConcurrency + 1)
|
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 {
|
eg.Go(func() error {
|
||||||
for node := range nodeCh {
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
case node := <-nodeCh:
|
||||||
expect--
|
expect--
|
||||||
if expect == 0 {
|
if expect == 0 {
|
||||||
close(nodeCh)
|
|
||||||
return nil
|
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)
|
nodes := t.extremityNodesFn(g)
|
||||||
t.run(ctx, g, eg, nodes, nodeCh)
|
t.run(ctx, g, eg, nodes, nodeCh)
|
||||||
|
|
||||||
err := eg.Wait()
|
return eg.Wait()
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this could be `graph.walk` or whatever
|
// Note: this could be `graph.walk` or whatever
|
||||||
|
@ -118,6 +118,7 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts
|
|||||||
if len(opts.User) > 0 {
|
if len(opts.User) > 0 {
|
||||||
service.User = opts.User
|
service.User = opts.User
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.CapAdd) > 0 {
|
if len(opts.CapAdd) > 0 {
|
||||||
service.CapAdd = append(service.CapAdd, opts.CapAdd...)
|
service.CapAdd = append(service.CapAdd, opts.CapAdd...)
|
||||||
service.CapDrop = utils.Remove(service.CapDrop, opts.CapAdd...)
|
service.CapDrop = utils.Remove(service.CapDrop, opts.CapAdd...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user