fix: potential deadLock caused by unlocking a non-existing lock (#15635)

This commit is contained in:
yudoutingle 2022-09-03 05:24:32 +08:00 committed by GitHub
parent 37e3f5de10
commit f4c56026a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,15 +60,6 @@ func (l *localLocker) String() string {
return globalEndpoints.Localhost()
}
func (l *localLocker) canTakeUnlock(resources ...string) bool {
for _, resource := range resources {
if !isWriteLock(l.lockMap[resource]) {
return false
}
}
return true
}
func (l *localLocker) canTakeLock(resources ...string) bool {
for _, resource := range resources {
_, lockTaken := l.lockMap[resource]
@ -129,12 +120,12 @@ func (l *localLocker) Unlock(_ context.Context, args dsync.LockArgs) (reply bool
err = nil
for _, resource := range args.Resources {
if !l.canTakeUnlock(resource) {
lri, ok := l.lockMap[resource]
if ok && !isWriteLock(lri) {
// Unless it is a write lock reject it.
err = fmt.Errorf("unlock attempted on a read locked entity: %s", resource)
continue
}
lri, ok := l.lockMap[resource]
if ok {
reply = l.removeEntry(resource, args, &lri) || reply
}