Skip to content

Commit

Permalink
Fix for Absorb that deadlocks when two objects are in the same lockbu…
Browse files Browse the repository at this point in the history
…cket
  • Loading branch information
lkarlslund committed Nov 4, 2021
1 parent 73af46e commit 2b742f4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ func (o *Object) runlock() {
// The sources empty shell should be discarded afterwards (i.e. not appear in an Objects collection)
func (o *Object) Absorb(source *Object) {
o.lock()
source.lock()
defer source.unlock()
if source.lockbucket() != o.lockbucket() {
source.lock()
defer source.unlock()
}
defer o.unlock()

target := o
for attr, values := range source.AttributeValueMap {
var val AttributeValues
tval := target.Attr(attr)
tval := target.attr(attr)
sval := values
tvalslice := tval.Slice()
svalslice := sval.Slice()
Expand Down Expand Up @@ -382,9 +384,7 @@ func (o *Object) OneAttrRendered(attr Attribute) string {
}

// Returns synthetic blank attribute value if it isn't set
func (o *Object) Attr(attr Attribute) AttributeValues {
o.lock()
defer o.unlock()
func (o *Object) attr(attr Attribute) AttributeValues {
if attrs, found := o.Find(attr); found {
if attrs == nil {
panic(fmt.Sprintf("Looked for attribute %v and found NIL value", attr.String()))
Expand All @@ -394,6 +394,13 @@ func (o *Object) Attr(attr Attribute) AttributeValues {
return NoValues{}
}

// Returns synthetic blank attribute value if it isn't set
func (o *Object) Attr(attr Attribute) AttributeValues {
o.lock()
defer o.unlock()
return o.attr(attr)
}

func (o *Object) OneAttrString(attr Attribute) string {
a, found := o.Find(attr)
if !found {
Expand Down

0 comments on commit 2b742f4

Please sign in to comment.