Merge pull request #1406 from felixdesouza/fds/fix-concurrent-map-write

Synchronise access to the map when printing.
This commit is contained in:
Justin Chadwell 2022-11-15 15:46:54 +00:00 committed by GitHub
commit 15bb14fcf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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
})