Skip to content

Commit

Permalink
consul lock
Browse files Browse the repository at this point in the history
Signed-off-by: crowu <[email protected]>
  • Loading branch information
5antelope committed Jun 11, 2021
1 parent 4449aa9 commit a87d6a5
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 a87d6a5

Please sign in to comment.