chore: fix deadlock in dbfake and incorrect lock types (#7218)

I manually went through every single dbfake function and ensured it has
the correct lock type depending on whether it writes or only reads.
There were a surprising amount of methods that had the wrong lock type
(Lock when only reading, or RLock when writing (!!!)).

This also manually fixes every method that acquires a RLock and then
calls a method that also acquires it's own RLock to use noLock methods
instead. You cannot rely on acquiring a RLock twice in the same
goroutine as RWMutex prioritizes any waiting Lock calls.

I tried writing a ruleguard rule for this but because of limitations in
ruleguard it doesn't seem possible.
This commit is contained in:
Dean Sheather
2023-04-20 04:53:34 -07:00
committed by GitHub
parent 5f5edb18b0
commit 528a0686c0
2 changed files with 77 additions and 47 deletions

View File

@ -68,7 +68,7 @@ func TestFilterError(t *testing.T) {
auth := &MockAuthorizer{
AuthorizeFunc: func(ctx context.Context, subject Subject, action Action, object Object) error {
// Authorize func always returns nil, unless the context is cancelled.
// Authorize func always returns nil, unless the context is canceled.
return ctx.Err()
},
}