Skip to content

Commit

Permalink
Merge pull request #30 from mgnsk/hotfix/reader-wg-race
Browse files Browse the repository at this point in the history
Lock record during delete
  • Loading branch information
mgnsk authored Apr 12, 2021
2 parents 0f9df62 + e87b3ca commit a1f2df4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ func (c *Cache) deleteLocked(key interface{}, target *interface{}) (value interf
if r.State() != active {
return nil, false
}
// Safe to lock r.mu on an active record
// while holding c.mu.
r.mu.Lock()
defer r.mu.Unlock()
value = r.value
if target != nil && !reflect.DeepEqual(value, *target) {
return nil, false
Expand Down

0 comments on commit a1f2df4

Please sign in to comment.