From f4d0a5eb22ab9c9f8215b4ec3da5171470345e49 Mon Sep 17 00:00:00 2001 From: Ashwanth Goli Date: Wed, 23 Oct 2024 16:51:02 +0530 Subject: [PATCH] retry: make max retries configurable Signed-off-by: Ashwanth Goli --- api.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 54a20e711..d2457d503 100644 --- a/api.go +++ b/api.go @@ -99,6 +99,7 @@ type Client struct { healthStatus int32 trailingHeaderSupport bool + maxRetries int } // Options for New method @@ -123,6 +124,10 @@ type Options struct { // Custom hash routines. Leave nil to use standard. CustomMD5 func() md5simd.Hasher CustomSHA256 func() md5simd.Hasher + + // Number of times a request is retried. Defaults to 10 retries if this option is not configured. + // Set to 1 to disable retries. + MaxRetries int } // Global constants. @@ -278,6 +283,8 @@ func privateNew(endpoint string, opts *Options) (*Client, error) { // healthcheck is not initialized clnt.healthStatus = unknown + clnt.maxRetries = opts.MaxRetries + // Return. return clnt, nil } @@ -592,7 +599,11 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ var retryable bool // Indicates if request can be retried. var bodySeeker io.Seeker // Extracted seeker from io.Reader. - reqRetry := MaxRetry // Indicates how many times we can retry the request + + reqRetry := MaxRetry // Indicates how many times we can retry the request + if c.maxRetries > 0 { + reqRetry = c.maxRetries + } if metadata.contentBody != nil { // Check if body is seekable then it is retryable.