Skip to content

Commit

Permalink
Fix for Object.lockwith deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 2, 2022
1 parent 512115c commit 8bca46a
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,21 @@ func (o *Object) runlock() {
threadsafeobjectmutexes[o.lockbucket()].RUnlock()
}

func (o *Object) lockwith(o2 *Object) {
if o2.id > o.id {
o, o2 = o2, o
}

ol := o.lockbucket()
o2l := o2.lockbucket()
var lockwithMu sync.Mutex

o.lock()
if ol != o2l {
func (o *Object) lockwith(o2 *Object) {
if o.lockbucket() == o2.lockbucket() {
o.lock()
} else {
lockwithMu.Lock() // Prevent deadlocks
o.lock()
o2.lock()
lockwithMu.Unlock()
}
}

func (o *Object) unlockwith(o2 *Object) {
if o2.id > o.id {
o, o2 = o2, o
}

ol := o.lockbucket()
o2l := o2.lockbucket()

if ol != o2l {
if o.lockbucket() != o2.lockbucket() {
o2.unlock()
}
o.unlock()
Expand Down

0 comments on commit 8bca46a

Please sign in to comment.