Skip to content

Commit

Permalink
clientv3: concurrency.Mutex.Lock() - preserve invariant
Browse files Browse the repository at this point in the history
Convenient invariant:
- if werr == nil then lock is supposed to be locked at the moment.

While we could not be confident in stronger invariant ('is exactly locked'),
it were inconvenient that previous code could return `werr == nil` after
Mutex.Unlock.

It could happen when ctx is canceled/timeouted exactly after waitDeletes
successfully returned werr == nil and before `<-ctx.Done()` checked.
While such situation is very rare, it is still possible.

fixes #10111
  • Loading branch information
funny-falcon authored and jingyih committed Oct 8, 2018
1 parent a4a8d07 commit 26cce20
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions clientv3/concurrency/mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ func (m *Mutex) Lock(ctx context.Context) error {

// wait for deletion revisions prior to myKey
hdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)
// release lock key if cancelled
select {
case <-ctx.Done():
// release lock key if wait failed
if werr != nil {
m.Unlock(client.Ctx())
default:
} else {
m.hdr = hdr
}
return werr
Expand Down

0 comments on commit 26cce20

Please sign in to comment.