Skip to content

Commit fe602ce

Browse files
authored
Merge pull request #98 from klihub/heads/refs/fixes/GetSpecErrors-rw-race
pkg/cdi: fix GetSpecErrors()/refresh read/write data race.
2 parents 9805f6f + 145cd82 commit fe602ce

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/cdi/cache.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,17 @@ func (c *Cache) GetVendorSpecs(vendor string) []*Spec {
409409
// GetSpecErrors returns all errors encountered for the spec during the
410410
// last cache refresh.
411411
func (c *Cache) GetSpecErrors(spec *Spec) []error {
412-
return c.errors[spec.GetPath()]
412+
var errors []error
413+
414+
c.Lock()
415+
defer c.Unlock()
416+
417+
if errs, ok := c.errors[spec.GetPath()]; ok {
418+
errors = make([]error, len(errs))
419+
copy(errors, errs)
420+
}
421+
422+
return errors
413423
}
414424

415425
// GetErrors returns all errors encountered during the last

0 commit comments

Comments
 (0)