Skip to content

Commit

Permalink
sleep if heartbeat returns 401
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed May 27, 2021
1 parent 40d0368 commit 2198d8e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ func (ca *Cagent) RunHeartbeat(interrupt chan struct{}) {
// for error code 429, wait 10 seconds and try again
retryIn = 10 * time.Second
log.Infof("RunHeartbeat: HTTP 429, too many requests, retrying in %v", retryIn)
} else if err == ErrHubUnauthorized {
// increase sleep time by 30 seconds until it is 1 hour
if ca.Config.Sleep < 60*60 {
ca.Config.Sleep += 30
}
retries = 0
retryIn = time.Duration(ca.Config.Sleep) * time.Second
log.Infof("Run: failed to send heartbeat to hub. unable to authorize with provided Hub credentials (HTTP 401). waiting %v seconds until next attempt", ca.Config.Sleep)
} else if err == ErrHubServerError {
// for error codes 5xx, wait for configured amount of time and try again
retryIn = time.Duration(ca.Config.OnHTTP5xxRetryInterval) * time.Second
Expand Down Expand Up @@ -379,6 +387,9 @@ func (ca *Cagent) sendHeartbeat() error {
if resp.StatusCode == http.StatusTooManyRequests {
return ErrHubTooManyRequests
}
if resp.StatusCode == http.StatusUnauthorized {
return ErrHubUnauthorized
}
if resp.StatusCode >= 500 && resp.StatusCode <= 599 {
return ErrHubServerError
}
Expand Down

0 comments on commit 2198d8e

Please sign in to comment.