From cd877c910c2c3971507944630abf5cb20ea74a40 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Wed, 7 Feb 2024 09:48:48 -0800 Subject: [PATCH] fix: fixes a possible race condition (#2762) --- internal/docker/container_store.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/docker/container_store.go b/internal/docker/container_store.go index 7d9f653b..ad581528 100644 --- a/internal/docker/container_store.go +++ b/internal/docker/container_store.go @@ -67,6 +67,13 @@ func (s *ContainerStore) init(ctx context.Context) { stats := make(chan ContainerStat) s.statsCollector.Subscribe(ctx, stats) + if containers, err := s.client.ListContainers(); err == nil { + for _, c := range containers { + c := c // create a new variable to avoid capturing the loop variable + s.containers.LoadOrStore(c.ID, &c) + } + } + for { select { case event := <-events: