Skip to content

Commit

Permalink
distinguish between transient and persistent errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Aug 10, 2020
1 parent f459aa6 commit a3b4f06
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func (v *vaultClient) establishConnection() {
// Create the retry timer and set initial duration to zero so it fires
// immediately
retryTimer := time.NewTimer(0)
initStatus := false
OUTER:
for {
select {
Expand All @@ -466,6 +467,16 @@ OUTER:
case <-retryTimer.C:
// Retry validating the token till success
if err := v.parseSelfToken(); err != nil {
// if parsing token fails, try to distinguish legitimate token error from transient Vault initialization/connection issue
if !initStatus {
if _, err := v.clientSys.Sys().Health(); err != nil {
v.logger.Warn("failed to contact Vault API", "retry", v.config.ConnectionRetryIntv, "error", err)
retryTimer.Reset(v.config.ConnectionRetryIntv)
continue OUTER
}
initStatus = true
}

v.logger.Error("failed to validate self token/role", "retry", v.config.ConnectionRetryIntv, "error", err)
retryTimer.Reset(v.config.ConnectionRetryIntv)
v.l.Lock()
Expand All @@ -474,6 +485,7 @@ OUTER:
v.l.Unlock()
continue OUTER
}

break OUTER
}
}
Expand Down

0 comments on commit a3b4f06

Please sign in to comment.