From eb9a01258ea169457d991d7cfc1bc2a40f9b19a5 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Thu, 13 Oct 2016 15:39:12 -0700 Subject: [PATCH] discovery: add upper limit for waiting on a retry Adding upper limit ensures that expoential backoff doesn't reach more than 5 min on a re-try. FIX #6648 --- discovery/discovery.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/discovery/discovery.go b/discovery/discovery.go index 3c06d3c7c..edc842ffb 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -52,7 +52,8 @@ var ( var ( // Number of retries discovery will attempt before giving up and erroring out. - nRetries = uint(math.MaxUint32) + nRetries = uint(math.MaxUint32) + maxExpoentialRetries = uint(8) ) // JoinCluster will connect to the discovery service at the given url, and @@ -268,9 +269,14 @@ func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) { func (d *discovery) logAndBackoffForRetry(step string) { d.retries++ - retryTime := time.Second * (0x1 << d.retries) - plog.Infof("%s: error connecting to %s, retrying in %s", step, d.url, retryTime) - d.clock.Sleep(retryTime) + // logAndBackoffForRetry stops exponential backoff when the retries are more than maxExpoentialRetries and is set to a constant backoff afterward. + retries := d.retries + if retries > maxExpoentialRetries { + retries = maxExpoentialRetries + } + retryTimeInSecond := time.Duration(0x1<