From 3f1516d3feb5cafc3434de7061f5aa51207144d6 Mon Sep 17 00:00:00 2001 From: Felix de Souza Date: Mon, 14 Nov 2022 15:46:18 +0000 Subject: [PATCH] Synchronise access to the map when printing. Signed-off-by: Felix de Souza --- util/imagetools/printers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/imagetools/printers.go b/util/imagetools/printers.go index 3e973a86..1d362819 100644 --- a/util/imagetools/printers.go +++ b/util/imagetools/printers.go @@ -8,6 +8,7 @@ import ( "os" "sort" "strings" + "sync" "text/tabwriter" "text/template" @@ -112,7 +113,9 @@ func (p *Printer) Print(raw bool, out io.Writer) error { } imageconfigs := make(map[string]*ocispecs.Image) + imageconfigsMutex := sync.Mutex{} buildinfos := make(map[string]*binfotypes.BuildInfo) + buildinfosMutex := sync.Mutex{} eg, _ := errgroup.WithContext(p.ctx) for _, platform := range p.platforms { @@ -122,12 +125,16 @@ func (p *Printer) Print(raw bool, out io.Writer) error { if err != nil { return err } else if img != nil { + imageconfigsMutex.Lock() imageconfigs[platforms.Format(platform)] = img + imageconfigsMutex.Unlock() } if bi, err := imageutil.BuildInfo(dtic); err != nil { return err } else if bi != nil { + buildinfosMutex.Lock() buildinfos[platforms.Format(platform)] = bi + buildinfosMutex.Unlock() } return nil })