mirror of https://github.com/minio/minio.git
fix: potential deadLock caused by unlocking a non-existing lock (#15635)
This commit is contained in:
parent
37e3f5de10
commit
f4c56026a2
|
@ -60,15 +60,6 @@ func (l *localLocker) String() string {
|
||||||
return globalEndpoints.Localhost()
|
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 {
|
func (l *localLocker) canTakeLock(resources ...string) bool {
|
||||||
for _, resource := range resources {
|
for _, resource := range resources {
|
||||||
_, lockTaken := l.lockMap[resource]
|
_, lockTaken := l.lockMap[resource]
|
||||||
|
@ -129,12 +120,12 @@ func (l *localLocker) Unlock(_ context.Context, args dsync.LockArgs) (reply bool
|
||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
for _, resource := range args.Resources {
|
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.
|
// Unless it is a write lock reject it.
|
||||||
err = fmt.Errorf("unlock attempted on a read locked entity: %s", resource)
|
err = fmt.Errorf("unlock attempted on a read locked entity: %s", resource)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
lri, ok := l.lockMap[resource]
|
|
||||||
if ok {
|
if ok {
|
||||||
reply = l.removeEntry(resource, args, &lri) || reply
|
reply = l.removeEntry(resource, args, &lri) || reply
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue