From e94530939173164b80faf6dd5870410cd3caf7fe Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Mon, 21 Oct 2024 16:53:04 +0100 Subject: [PATCH] fix(compose): race condition (#2842) Fix a race condition in compose module when setting up multiple containers. --- modules/compose/compose_api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/compose/compose_api.go b/modules/compose/compose_api.go index 2c852bdaff..c84f1af6ce 100644 --- a/modules/compose/compose_api.go +++ b/modules/compose/compose_api.go @@ -379,6 +379,7 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro // Lookup the containers for each service and connect them // to the reaper if needed. + var termSignalsMtx sync.Mutex for _, srv := range d.project.Services { srv := srv errGrpContainers.Go(func() error { @@ -394,6 +395,9 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro } dc.SetTerminationSignal(termSignal) + + termSignalsMtx.Lock() + defer termSignalsMtx.Unlock() termSignals = append(termSignals, termSignal) }