From 560faa362c2f6121d2afb614c54f4b83f2136e2c Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Wed, 16 Sep 2020 07:42:20 +0200 Subject: [PATCH] fix: do not wait on zero retries Signed-off-by: Yoan Blanc --- httpclient/client.go | 10 ++++++---- httpclient/options_test.go | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index 5f03c5b..cc51d7d 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -143,6 +143,11 @@ func (c *Client) Do(request *http.Request) (*http.Response, error) { response.Body.Close() } + if i > 0 { + backoffTime := c.retrier.NextInterval(i - 1) + time.Sleep(backoffTime) + } + c.reportRequestStart(request) var err error response, err = c.client.Do(request) @@ -155,15 +160,12 @@ func (c *Client) Do(request *http.Request) (*http.Response, error) { if err != nil { multiErr.Push(err.Error()) c.reportError(request, err) - backoffTime := c.retrier.NextInterval(i) - time.Sleep(backoffTime) continue } + c.reportRequestEnd(request, response) if response.StatusCode >= http.StatusInternalServerError { - backoffTime := c.retrier.NextInterval(i) - time.Sleep(backoffTime) continue } diff --git a/httpclient/options_test.go b/httpclient/options_test.go index b92ce71..2e93673 100644 --- a/httpclient/options_test.go +++ b/httpclient/options_test.go @@ -128,6 +128,5 @@ func ExampleWithRetrier() { // Output: retry attempt 0 // retry attempt 1 // retry attempt 2 - // retry attempt 3 // error }