Skip to content

Commit df2a8f5

Browse files
authored
retry: make max retries configurable (#2013)
1 parent 22d521d commit df2a8f5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

api.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type Client struct {
9999
healthStatus int32
100100

101101
trailingHeaderSupport bool
102+
maxRetries int
102103
}
103104

104105
// Options for New method
@@ -123,6 +124,10 @@ type Options struct {
123124
// Custom hash routines. Leave nil to use standard.
124125
CustomMD5 func() md5simd.Hasher
125126
CustomSHA256 func() md5simd.Hasher
127+
128+
// Number of times a request is retried. Defaults to 10 retries if this option is not configured.
129+
// Set to 1 to disable retries.
130+
MaxRetries int
126131
}
127132

128133
// Global constants.
@@ -278,6 +283,11 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
278283
// healthcheck is not initialized
279284
clnt.healthStatus = unknown
280285

286+
clnt.maxRetries = MaxRetry
287+
if opts.MaxRetries > 0 {
288+
clnt.maxRetries = opts.MaxRetries
289+
}
290+
281291
// Return.
282292
return clnt, nil
283293
}
@@ -590,9 +600,9 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ
590600
return nil, errors.New(c.endpointURL.String() + " is offline.")
591601
}
592602

593-
var retryable bool // Indicates if request can be retried.
594-
var bodySeeker io.Seeker // Extracted seeker from io.Reader.
595-
reqRetry := MaxRetry // Indicates how many times we can retry the request
603+
var retryable bool // Indicates if request can be retried.
604+
var bodySeeker io.Seeker // Extracted seeker from io.Reader.
605+
var reqRetry = c.maxRetries // Indicates how many times we can retry the request
596606

597607
if metadata.contentBody != nil {
598608
// Check if body is seekable then it is retryable.

0 commit comments

Comments
 (0)