Skip to content

Commit f954941

Browse files
committed
fix race condition when deleting key lock
1 parent 92e243b commit f954941

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

key_locker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func (l *InMemoryKeyLocker[Key]) Lock(key Key) func() {
4646
}
4747
item.m.Unlock()
4848
if atomic.AddInt32(&item.ref, -1) <= 0 {
49+
l.root.Lock()
50+
defer l.root.Unlock()
4951
delete(l.locks, key)
5052
}
5153
unlocked = true

0 commit comments

Comments
 (0)