Skip to content

Commit

Permalink
Merge pull request #8310 from narcsfz/ywu/lock
Browse files Browse the repository at this point in the history
Use consul lock properly
  • Loading branch information
deepthi authored Jul 8, 2021
2 parents 6418fe9 + a87d6a5 commit 9fa6ff4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions go/vt/topo/consultopo/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ func (s *Server) Lock(ctx context.Context, dirPath, contents string) (topo.LockD

// We are the only ones trying to lock now.
lost, err := l.Lock(ctx.Done())
if err != nil {
if err != nil || lost == nil {
// Failed to lock, give up our slot in locks map.
// Close the channel to unblock anyone else.
s.mu.Lock()
delete(s.locks, lockPath)
s.mu.Unlock()
close(li.done)

// Consul will return empty leaderCh with nil error if we cannot get lock before the timeout
// therefore we return a timeout error here
if lost == nil {
return nil, topo.NewError(topo.Timeout, lockPath)
}
return nil, err
}

Expand Down

0 comments on commit 9fa6ff4

Please sign in to comment.