From f4c56026a28d836d4a5de109f5de34e19ace04a0 Mon Sep 17 00:00:00 2001 From: yudoutingle <32899376+yudoutingle@users.noreply.github.com> Date: Sat, 3 Sep 2022 05:24:32 +0800 Subject: [PATCH] fix: potential deadLock caused by unlocking a non-existing lock (#15635) --- cmd/local-locker.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/cmd/local-locker.go b/cmd/local-locker.go index f89efcc7c..c6e9a3ffb 100644 --- a/cmd/local-locker.go +++ b/cmd/local-locker.go @@ -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 }