Configuration for automatic retry for idempotent calls

This commit is contained in:
michael.kochegarov
2017-11-30 11:14:35 +03:00
committed by Erik Dubbelboer
parent 2cc8e6be6d
commit 19d2d06ab5
+12 -1
View File
@@ -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)