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 <matthew.johnson@intel.com>
This commit is contained in:
Matthew Johnson
2018-08-23 16:05:06 -07:00
committed by tmarcu
parent 04c713623a
commit 91434ca5fd
+8 -9
View File
@@ -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)
}