Skip to content

Commit

Permalink
solver: fix exporters unsafely sharing records
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Oct 9, 2021
1 parent ba673bb commit 4cec7a0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions solver/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type exporter struct {
records []*CacheRecord
record *CacheRecord

res []CacheExporterRecord
edge *edge // for secondaryExporters
override *bool
}
Expand Down Expand Up @@ -52,9 +51,10 @@ func addBacklinks(t CacheExporterTarget, rec CacheExporterRecord, cm *cacheManag
return rec, nil
}

type backlinkT struct{}
type contextT string

var backlinkKey = backlinkT{}
var backlinkKey = contextT("solver/exporter/backlinks")
var resKey = contextT("solver/exporter/res")

func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt CacheExportOpt) ([]CacheExporterRecord, error) {
var bkm map[string]CacheExporterRecord
Expand All @@ -66,8 +66,16 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
bkm = bk.(map[string]CacheExporterRecord)
}

var res map[*exporter][]CacheExporterRecord
if r := ctx.Value(resKey); r == nil {
res = map[*exporter][]CacheExporterRecord{}
ctx = context.WithValue(ctx, resKey, res)
} else {
res = r.(map[*exporter][]CacheExporterRecord)
}

if t.Visited(e) {
return e.res, nil
return res[e], nil
}
t.Visit(e)

Expand Down Expand Up @@ -180,9 +188,9 @@ func (e *exporter) ExportTo(ctx context.Context, t CacheExporterTarget, opt Cach
}
}

e.res = allRec
res[e] = allRec

return e.res, nil
return allRec, nil
}

func getBestResult(records []*CacheRecord) *CacheRecord {
Expand Down

0 comments on commit 4cec7a0

Please sign in to comment.