From cc5f2e98b763b76f1b0d705efcedaa2ea031ad09 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 28 Apr 2022 10:18:27 +0100 Subject: [bugfix] Fix possible race condition in federatingdb (#490) Signed-off-by: kim --- .../superseriousbusiness/activity/pub/util.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'vendor/github.com/superseriousbusiness/activity/pub/util.go') diff --git a/vendor/github.com/superseriousbusiness/activity/pub/util.go b/vendor/github.com/superseriousbusiness/activity/pub/util.go index d8937bba2..a0675b76e 100644 --- a/vendor/github.com/superseriousbusiness/activity/pub/util.go +++ b/vendor/github.com/superseriousbusiness/activity/pub/util.go @@ -753,7 +753,8 @@ func mustHaveActivityActorsMatchObjectActors(c context.Context, actors vocab.ActivityStreamsActorProperty, op vocab.ActivityStreamsObjectProperty, newTransport func(c context.Context, actorBoxIRI *url.URL, gofedAgent string) (t Transport, err error), - boxIRI *url.URL) error { + boxIRI *url.URL, +) error { activityActorMap := make(map[string]bool, actors.Len()) for iter := actors.Begin(); iter != actors.End(); iter = iter.Next() { id, err := ToId(iter) @@ -808,7 +809,8 @@ func mustHaveActivityActorsMatchObjectActors(c context.Context, func add(c context.Context, op vocab.ActivityStreamsObjectProperty, target vocab.ActivityStreamsTargetProperty, - db Database) error { + db Database, +) error { opIds := make([]*url.URL, 0, op.Len()) for iter := op.Begin(); iter != op.End(); iter = iter.Next() { id, err := ToId(iter) @@ -828,10 +830,11 @@ func add(c context.Context, // Create anonymous loop function to be able to properly scope the defer // for the database lock at each iteration. loopFn := func(t *url.URL) error { - if err := db.Lock(c, t); err != nil { + unlock, err := db.Lock(c, t) + if err != nil { return err } - defer db.Unlock(c, t) + defer unlock() if owns, err := db.Owns(c, t); err != nil { return err } else if !owns { @@ -889,7 +892,8 @@ func add(c context.Context, func remove(c context.Context, op vocab.ActivityStreamsObjectProperty, target vocab.ActivityStreamsTargetProperty, - db Database) error { + db Database, +) error { opIds := make(map[string]bool, op.Len()) for iter := op.Begin(); iter != op.End(); iter = iter.Next() { id, err := ToId(iter) @@ -909,10 +913,11 @@ func remove(c context.Context, // Create anonymous loop function to be able to properly scope the defer // for the database lock at each iteration. loopFn := func(t *url.URL) error { - if err := db.Lock(c, t); err != nil { + unlock, err := db.Lock(c, t) + if err != nil { return err } - defer db.Unlock(c, t) + defer unlock() if owns, err := db.Owns(c, t); err != nil { return err } else if !owns { -- cgit v1.3