Skip to content

Commit

Permalink
Merge pull request #344 from reubenmiller/disable-retry-by-default
Browse files Browse the repository at this point in the history
fix(retry): disable retries by default
  • Loading branch information
reubenmiller authored Feb 17, 2024
2 parents 93a2327 + c360a75 commit 3aa2a7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions pkg/cmd/factory/c8yclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,29 @@ func CreateCumulocityClient(f *cmdutil.Factory, sessionFile, username, password
WithCompression(cfg.ShouldUseCompression()),
)

// Use retry client
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = cfg.HTTPRetryMax()
retryClient.RetryWaitMin = cfg.HTTPRetryWaitMin()
retryClient.RetryWaitMax = cfg.HTTPRetryWaitMax()
retryClient.Logger = RetryLogger{l: log}
retryClient.ErrorHandler = func(resp *http.Response, err error, numTries int) (*http.Response, error) {
// Pass error back so that the activity log is processed
log.Warnf("Giving up after %d attempt/s. err=%s", numTries, err)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
var httpClient *http.Client
if cfg.HTTPRetryMax() > 0 {
// Use retry client
// Note: Don't use the retry client unless we have to as it will the body (if set)
// of outgoing HTTP requests into memory (and it affects the loading as well)
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = cfg.HTTPRetryMax()
retryClient.RetryWaitMin = cfg.HTTPRetryWaitMin()
retryClient.RetryWaitMax = cfg.HTTPRetryWaitMax()
retryClient.Logger = RetryLogger{l: log}
retryClient.ErrorHandler = func(resp *http.Response, err error, numTries int) (*http.Response, error) {
// Pass error back so that the activity log is processed
log.Warnf("Giving up after %d attempt/s. err=%s", numTries, err)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return resp, err
}
return resp, err
retryClient.HTTPClient = internalHttpClient
httpClient = retryClient.StandardClient()
} else {
httpClient = internalHttpClient
}
retryClient.HTTPClient = internalHttpClient
httpClient := retryClient.StandardClient()

cacheBodyPaths := cfg.CacheBodyKeys()
if len(cacheBodyPaths) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/cliConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (c *Config) bindSettings() {

// HTTP settings
WithBindEnv(SettingsUseCompression, true),
WithBindEnv(SettingsHTTPMaxRetries, 3),
WithBindEnv(SettingsHTTPMaxRetries, 0),
WithBindEnv(SettingsHTTPRetryWaitMax, "50s"),
WithBindEnv(SettingsHTTPRetryWaitMin, "5s"),

Expand Down

0 comments on commit 3aa2a7c

Please sign in to comment.