Closed dctalbot closed 8 months ago
The Range
method acquires a lock on each shard and releases it only after the callback function finishes execution. However, the Delete
method attempts to acquire a lock on the same shard within the callback function, creating a deadlock because the Range method's lock is still held.
Try delaying the deletion operation until the Range
method completes:
func (c *Cache) evictCollection(name string) {
shouldDelete := []string{}
c.tcache.Range(func(k string, v []byte) bool {
if getCollectionName(k) == name {
fmt.Println("evicting", k) // print eviction notice
shouldDelete = append(shouldDelete, k)
// c.tcache.Delete(k)
}
return true
})
for _, key := range shouldDelete {
c.tcache.Delete(key)
}
}
That seems to have been the issue. Thank you for the quick reply!
Hi, I'm seeing a dead lock when I try to use this package.
Code to reproduce:
go run main.go