forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
have the consul client manage the lock session
When a consul lock is lost, there is a possibility that the associated session is still active. Most commonly, the long request to watch the lock key may error out, while the session is continually refreshed at a rate of TTL/2. First have the lock monitor retry the lock internally for at least 10 seconds (5 attempts with the default 2 second wait time). In most cases this will reconnect on the first try, keeping the lock channel open. If the consul lock can't recover itself, then cancel the session as soon as possible (terminating the PreiodicRenew will call Session.Destroy), and start over. In the worse case, the consul agents were split, and the session still exists on the leader so we may need to wait for the old session TTL, plus the LockWait time to renew the lock. We use a Context for the cancellation channels here, because that removes the need to worry about double-closes and nil channels. It requires an awkward adapter goroutine for now to convert the Done() `<-chan` to a `chan` for PeriodicRenew, but makes the rest of the code safer in the long run.
- Loading branch information
Showing
1 changed file
with
122 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters