From 5e97046c2f79e2d1f5dee8e09328533be1862f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Fri, 3 May 2024 23:49:32 +0200 Subject: [PATCH] fix(compose): avoid race conditions when caching services (#2528) --- 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 ac52d1b335..e5d1ea8a26 100644 --- a/modules/compose/compose_api.go +++ b/modules/compose/compose_api.go @@ -370,6 +370,8 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) error { }() } + d.containersLock.Lock() + defer d.containersLock.Unlock() d.containers[srv.Name] = dc return nil @@ -398,6 +400,8 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) error { } // cache all the containers on compose.up + d.containersLock.Lock() + defer d.containersLock.Unlock() d.containers[svc] = target return strategy.WaitUntilReady(errGrpCtx, target)