hashicorp / hashicorp/consul

[docs] Update api godoc for Lock() and Unlock()

Open
#5,686 0 comments 0 reactions 0 assignees View on GitHub
theme/operator-usability type/docs
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
2d 6h
Merged PRs (30d)
43

Description

Based on #4935 and #4902

#### Description
Currently it's unclear from the Go api documentation that `Unlock()` **must** be called after `Lock()`.

This results in situations where if `Unlock()` is not called:

- The routine that monitors the lock (`monitorLock`) closes the `leaderCh` if it believes the leadership was lost
- Despite that signal, the client does not fully acknowledge that the lock was lost. This is because `l.isHeld` is only set to false by `Unlock()`.
- When the client tries to re-acquire the lock, it gets the unexpected error: `Lock already held`

#### Solution
- Update Lock() and Unlock() documentation in the code
- Add an [example](https://godoc.org/github.com/fluhus/godoc-tricks#Examples). Could re-use the one from the original PR: https://github.com/hashicorp/consul/pull/4935#issuecomment-437383416

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.