Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consul lock properly #8310

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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