Skip to content

Commit

Permalink
Support infinity retry
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Jan 31, 2023
1 parent b064bf0 commit bc78993
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ func (c *Client) getRetryOption() *retryOption {

// SetCommonRetryCount enables retry and set the maximum retry count for requests
// fired from the client.
// It will retry infinitely if count is negative.
func (c *Client) SetCommonRetryCount(count int) *Client {
c.getRetryOption().MaxRetries = count
return c
Expand Down
5 changes: 3 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func (r *Request) Do(ctx ...context.Context) *Response {
if r.error != nil {
return r.newErrorResponse(r.error)
}
if r.retryOption != nil && r.retryOption.MaxRetries > 0 && r.unReplayableBody != nil { // retryable request should not have unreplayable Body
if r.retryOption != nil && r.retryOption.MaxRetries != 0 && r.unReplayableBody != nil { // retryable request should not have unreplayable Body
return r.newErrorResponse(errRetryableWithUnReplayableBody)
}
resp, _ := r.do()
Expand Down Expand Up @@ -578,7 +578,7 @@ func (r *Request) do() (resp *Response, err error) {
resp, err = r.client.roundTrip(r)
}

if r.retryOption == nil || r.RetryAttempt >= r.retryOption.MaxRetries { // absolutely cannot retry.
if r.retryOption == nil || (r.RetryAttempt >= r.retryOption.MaxRetries && r.retryOption.MaxRetries > 0) { // absolutely cannot retry.
return
}

Expand Down Expand Up @@ -1017,6 +1017,7 @@ func (r *Request) getRetryOption() *retryOption {
}

// SetRetryCount enables retry and set the maximum retry count.
// It will retry infinitely if count is negative.
func (r *Request) SetRetryCount(count int) *Request {
r.getRetryOption().MaxRetries = count
return r
Expand Down

0 comments on commit bc78993

Please sign in to comment.