terraform/backend/remote-state/consul
James Bardin bcb11f6d89 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.
2017-07-14 14:42:42 -04:00
..
backend.go backend/consul: support "lock" option to disable locking 2017-03-14 17:59:10 -07:00
backend_state.go relock consul when lock is lost 2017-05-30 14:38:33 -04:00
backend_test.go backend/consul: rebase and modify gzip test 2017-03-14 17:59:54 -07:00
client.go have the consul client manage the lock session 2017-07-14 14:42:42 -04:00
client_test.go Test losing and reacquiring a consul lock 2017-05-30 14:38:33 -04:00