[bugfix] Fix possible race condition in federatingdb (#490)

Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2022-04-28 10:18:27 +01:00 committed by GitHub
commit cc5f2e98b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 131 additions and 220 deletions

View file

@ -64,18 +64,20 @@ func NewActivityStreamsHandlerScheme(db Database, clock Clock, scheme string) Ha
}
isASRequest = true
id := requestId(r, scheme)
var unlock func()
// Lock and obtain a copy of the requested ActivityStreams value
err = db.Lock(c, id)
unlock, err = db.Lock(c, id)
if err != nil {
return
}
// WARNING: Unlock not deferred
t, err := db.Get(c, id)
unlock() // unlock even on error
if err != nil {
db.Unlock(c, id)
return
}
db.Unlock(c, id)
// Unlock must have been called by this point and in every
// branch above
if t == nil {