From 1af4694889301b0bd06994c6c023b42458191e84 Mon Sep 17 00:00:00 2001 From: Roman Vynar Date: Tue, 11 Jun 2024 14:23:39 +0300 Subject: [PATCH] Fix concurrent map iteration and map write --- registry/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/registry/client.go b/registry/client.go index b8a7962..3e8cca2 100644 --- a/registry/client.go +++ b/registry/client.go @@ -280,11 +280,15 @@ func (c *Client) SubRepoTagCounts(repoPath string, repos []string) map[string]in if repoPath != "" { subRepo = repoPath + "/" + r } + + // Acquire lock to prevent concurrent map iteration and map write. + c.tagCountsMux.Lock() for k, v := range c.tagCounts { if k == subRepo || strings.HasPrefix(k, subRepo+"/") { counts[subRepo] = counts[subRepo] + v } } + c.tagCountsMux.Unlock() } return counts }