Skip to content

Commit

Permalink
fix race condition when deleting key lock
Browse files Browse the repository at this point in the history
  • Loading branch information
abihf committed Mar 21, 2022
1 parent 92e243b commit f954941
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions key_locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (l *InMemoryKeyLocker[Key]) Lock(key Key) func() {
}
item.m.Unlock()
if atomic.AddInt32(&item.ref, -1) <= 0 {
l.root.Lock()
defer l.root.Unlock()
delete(l.locks, key)
}
unlocked = true
Expand Down

0 comments on commit f954941

Please sign in to comment.