Skip to content

Commit 7079ed1

Browse files
committed
Extra safety
1 parent 74d7252 commit 7079ed1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cache.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ func (c *Cache) Evict(key interface{}) (interface{}, bool) {
165165
// don't lock it to prevent deadlock.
166166
return nil, false
167167
}
168-
c.records.Delete(key)
168+
old, ok := c.records.LoadAndDelete(key)
169+
if !ok || old.(*record) != r {
170+
panic("evcache: inconsistent map state")
171+
}
169172
return c.finalize(key, r.(*record))
170173
}
171174

@@ -354,7 +357,10 @@ func (c *Cache) deleteIfEqualsLocked(key interface{}, r *record) bool {
354357
if old.(*record) != r {
355358
return false
356359
}
357-
c.records.Delete(key)
360+
old, ok = c.records.LoadAndDelete(key)
361+
if !ok || old.(*record) != r {
362+
panic("evcache: inconsistent map state")
363+
}
358364
return true
359365
}
360366

0 commit comments

Comments
 (0)