Skip to content

Commit

Permalink
core: Don't shutdown if key upgrades fail due to canceled context (#7070
Browse files Browse the repository at this point in the history
)

* core: Don't shutdown if key upgrades fail due to canceled context

* Continue if we are not shutting down
  • Loading branch information
briankassouf authored Jul 5, 2019
1 parent c3f0f96 commit 8e93f59
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions vault/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -472,18 +473,31 @@ func (c *Core) waitForLeadership(newLeaderCh chan func(), manualStepDownCh, stop
}

if err := c.performKeyUpgrades(activeCtx); err != nil {
// We call this in a goroutine so that we can give up the
// statelock and have this shut us down; sealInternal has a
// workflow where it watches for the stopCh to close so we want
// to return from here
c.logger.Error("error performing key upgrades", "error", err)
go c.Shutdown()

// If we fail due to anything other than a context canceled
// error we should shutdown as we may have the incorrect Keys.
if !strings.Contains(err.Error(), context.Canceled.Error()) {
// We call this in a goroutine so that we can give up the
// statelock and have this shut us down; sealInternal has a
// workflow where it watches for the stopCh to close so we want
// to return from here
go c.Shutdown()
}

c.heldHALock = nil
lock.Unlock()
close(continueCh)
c.stateLock.Unlock()
metrics.MeasureSince([]string{"core", "leadership_setup_failed"}, activeTime)
return

// If we are shutting down we should return from this function,
// otherwise continue
if !strings.Contains(err.Error(), context.Canceled.Error()) {
continue
} else {
return
}
}
}

Expand Down

0 comments on commit 8e93f59

Please sign in to comment.