Skip to content

Commit

Permalink
vault: recover from standby losing etcd lease (#3031) (#3511)
Browse files Browse the repository at this point in the history
This change makes these errors transient instead of permanent:

[ERROR] core: failed to acquire lock: error=etcdserver: requested lease not found

After this change, there can still be one of these errors when a
standby vault that lost its lease tries to become leader, but on the
next lock acquisition attempt a new session will be created. With this
new session, the standby will be able to become the leader.
  • Loading branch information
bhiggins authored and jefferai committed Nov 3, 2017
1 parent 8004f05 commit 3d51b92
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions physical/etcd/etcd3.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ func (c *EtcdLock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error) {
return nil, EtcdLockHeldError
}

select {
case _, ok := <-c.etcdSession.Done():
if !ok {
// The session's done channel is closed, so the session is over,
// and we need a new one
session, err := concurrency.NewSession(c.etcd, concurrency.WithTTL(etcd3LockTimeoutInSeconds))
if err != nil {
return nil, err
}
c.etcdSession = session
c.etcdMu = concurrency.NewMutex(session, c.prefix)
}
default:
}

ctx, cancel := context.WithCancel(context.Background())
go func() {
<-stopCh
Expand Down

0 comments on commit 3d51b92

Please sign in to comment.