From 19d2d06ab58c801532cbf41eff72378302acbadc Mon Sep 17 00:00:00 2001 From: "michael.kochegarov" Date: Thu, 30 Nov 2017 11:14:35 +0300 Subject: [PATCH] Configuration for automatic retry for idempotent calls --- client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 4ff7fd4..2e00232 100644 --- a/client.go +++ b/client.go @@ -447,6 +447,9 @@ const DefaultMaxConnsPerHost = 512 // connection is closed. const DefaultMaxIdleConnDuration = 10 * time.Second +// DefaultMaxIdemponentCallAttempts is the default idempotent calls attempts count. +const DefaultMaxIdemponentCallAttempts = 5 + // DialFunc must establish connection to addr. // // There is no need in establishing TLS (SSL) connection for https. @@ -526,6 +529,11 @@ type HostClient struct { // after DefaultMaxIdleConnDuration. MaxIdleConnDuration time.Duration + // Maximum number of attempts for idempotent calls + // + // DefaultMaxIdemponentCallAttempts is used if not set. + MaxIdemponentCallAttempts int + // Per-connection buffer size for responses' reading. // This also limits the maximum header size. // @@ -979,7 +987,10 @@ var errorChPool sync.Pool func (c *HostClient) Do(req *Request, resp *Response) error { var err error var retry bool - const maxAttempts = 5 + maxAttempts := c.MaxIdemponentCallAttempts + if maxAttempts <= 0 { + maxAttempts = DefaultMaxIdemponentCallAttempts + } attempts := 0 atomic.AddUint64(&c.pendingRequests, 1)