From 91434ca5fd247e177af17494c9d6275a2c19ae90 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 23 Aug 2018 15:46:01 -0700 Subject: [PATCH] bundles: Fix race condition on map.Range When ranging over the syncmap to add packages to a bundle we were mistakenly ranging over the entire set of bundles and adding all bundle packages to the same bundle (nondeterministically, since we were doing concurrent writes to a syncmap). In reality we just need to range over the repoPkgMap itself and not load it from the syncmap at all. Do this operation before even storing it. Signed-off-by: Matthew Johnson --- builder/bundles.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/builder/bundles.go b/builder/bundles.go index bb9a3aa..d6d0717 100644 --- a/builder/bundles.go +++ b/builder/bundles.go @@ -383,16 +383,15 @@ func resolvePackages(numWorkers int, set bundleSet, packagerCmd []string, emptyD // TODO: parseNoopInstall may fail, so consider a way to stop the processing // once we find that failure. See how errorCh works in fullfiles.go. - bundleRepoPkgs.Store(bundle.Name, parseNoopInstall(outBuf.String())) - - bundleRepoPkgs.Range(func(key, val interface{}) bool { - for _, r := range val.(repoPkgMap) { - for _, p := range r { - bundle.AllPackages[p] = true - } + rpm := parseNoopInstall(outBuf.String()) + for _, pkgs := range rpm { + // Add packages to bundle's AllPackages + for _, pkg := range pkgs { + bundle.AllPackages[pkg] = true } - return true - }) + } + + bundleRepoPkgs.Store(bundle.Name, rpm) fmt.Printf("... done with %s\n", bundle.Name) }