Skip to content

Commit

Permalink
Add a missing retry in consul client (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaleman committed Jul 26, 2016
1 parent 4cebe43 commit 179d836
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions consulClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,24 @@ func (cp *consulPlugin) NewClient(endpoints []string) (API, error) {
// verify we can reach the consul
_, _, err = client.KV().List("/", nil)
if err != nil {
log.Errorf("Error connecting to consul. Err: %v", err)
return nil, err
if api.IsServerError(err) || strings.Contains(err.Error(), "EOF") ||
strings.Contains(err.Error(), "connection refused") {
for i := 0; i < maxConsulRetries; i++ {
_, _, err = client.KV().List("/", nil)
if err == nil {
break
}

// Retry after a delay
time.Sleep(time.Second)
}
}

// return error if it failed after retries
if err != nil {
log.Errorf("Error connecting to consul. Err: %v", err)
return nil, err
}
}

return cc, nil
Expand Down

0 comments on commit 179d836

Please sign in to comment.