Skip to content

Commit

Permalink
Merge pull request #98 from klihub/heads/refs/fixes/GetSpecErrors-rw-…
Browse files Browse the repository at this point in the history
…race

pkg/cdi: fix GetSpecErrors()/refresh read/write data race.
  • Loading branch information
bart0sh authored Nov 11, 2022
2 parents 9805f6f + 145cd82 commit fe602ce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cdi/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,17 @@ func (c *Cache) GetVendorSpecs(vendor string) []*Spec {
// GetSpecErrors returns all errors encountered for the spec during the
// last cache refresh.
func (c *Cache) GetSpecErrors(spec *Spec) []error {
return c.errors[spec.GetPath()]
var errors []error

c.Lock()
defer c.Unlock()

if errs, ok := c.errors[spec.GetPath()]; ok {
errors = make([]error, len(errs))
copy(errors, errs)
}

return errors
}

// GetErrors returns all errors encountered during the last
Expand Down

0 comments on commit fe602ce

Please sign in to comment.