diff --git a/logreader.go b/logreader.go index 9c582eba3..036186e97 100644 --- a/logreader.go +++ b/logreader.go @@ -136,11 +136,11 @@ func (r *LogReader) read(l []byte) (int, error) { } // backoff will perform exponential backoff based on the iteration and -// limited by the provided min and max (in milliseconds) durations. -func backoff(min, max float64, iter int) time.Duration { - backoff := math.Pow(2, float64(iter)/5) * min - if backoff > max { - backoff = max +// limited by the provided minimum and maximum (in milliseconds) durations. +func backoff(minimum, maximum float64, iter int) time.Duration { + backoff := math.Pow(2, float64(iter)/5) * minimum + if backoff > maximum { + backoff = maximum } return time.Duration(backoff) * time.Millisecond } diff --git a/tfe.go b/tfe.go index a4f40be3e..70ee414f6 100644 --- a/tfe.go +++ b/tfe.go @@ -617,36 +617,36 @@ func (c *Client) retryHTTPCheck(ctx context.Context, resp *http.Response, err er // retryHTTPBackoff provides a generic callback for Client.Backoff which // will pass through all calls based on the status code of the response. -func (c *Client) retryHTTPBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { +func (c *Client) retryHTTPBackoff(minimum, maximum time.Duration, attemptNum int, resp *http.Response) time.Duration { if c.retryLogHook != nil { c.retryLogHook(attemptNum, resp) } // Use the rate limit backoff function when we are rate limited. if resp != nil && resp.StatusCode == 429 { - return rateLimitBackoff(min, max, resp) + return rateLimitBackoff(minimum, maximum, resp) } // Set custom duration's when we experience a service interruption. - min = 700 * time.Millisecond - max = 900 * time.Millisecond + minimum = 700 * time.Millisecond + maximum = 900 * time.Millisecond - return retryablehttp.LinearJitterBackoff(min, max, attemptNum, resp) + return retryablehttp.LinearJitterBackoff(minimum, maximum, attemptNum, resp) } // rateLimitBackoff provides a callback for Client.Backoff which will use the // X-RateLimit_Reset header to determine the time to wait. We add some jitter // to prevent a thundering herd. // -// min and max are mainly used for bounding the jitter that will be added to +// minimum and maximum are mainly used for bounding the jitter that will be added to // the reset time retrieved from the headers. But if the final wait time is -// less than min, min will be used instead. -func rateLimitBackoff(min, max time.Duration, resp *http.Response) time.Duration { +// less than minimum, minimum will be used instead. +func rateLimitBackoff(minimum, maximum time.Duration, resp *http.Response) time.Duration { // rnd is used to generate pseudo-random numbers. rnd := rand.New(rand.NewSource(time.Now().UnixNano())) // First create some jitter bounded by the min and max durations. - jitter := time.Duration(rnd.Float64() * float64(max-min)) + jitter := time.Duration(rnd.Float64() * float64(maximum-minimum)) if resp != nil && resp.Header.Get(_headerRateReset) != "" { v := resp.Header.Get(_headerRateReset) @@ -655,12 +655,12 @@ func rateLimitBackoff(min, max time.Duration, resp *http.Response) time.Duration log.Fatal(err) } // Only update min if the given time to wait is longer - if reset > 0 && time.Duration(reset*1e9) > min { - min = time.Duration(reset * 1e9) + if reset > 0 && time.Duration(reset*1e9) > minimum { + minimum = time.Duration(reset * 1e9) } } - return min + jitter + return minimum + jitter } type rawAPIMetadata struct {