From 9603bfa602469872aa34ad4c19902151277ca5ac Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 23 Apr 2019 20:07:29 -0700 Subject: [PATCH] watchtower/wtclient/session_negotiator: don't backoff on first attempt --- watchtower/wtclient/session_negotiator.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/watchtower/wtclient/session_negotiator.go b/watchtower/wtclient/session_negotiator.go index 19c7347c..e16296fa 100644 --- a/watchtower/wtclient/session_negotiator.go +++ b/watchtower/wtclient/session_negotiator.go @@ -228,7 +228,7 @@ func (n *sessionNegotiator) negotiate() { // On the first pass, initialize the backoff to our configured min // backoff. - backoff := n.cfg.MinBackoff + var backoff time.Duration retryWithBackoff: // If we are retrying, wait out the delay before continuing. @@ -244,13 +244,24 @@ retryWithBackoff: // iterator to ensure the results are fresh. n.cfg.Candidates.Reset() for { + select { + case <-n.quit: + return + default: + } + // Pull the next candidate from our list of addresses. tower, err := n.cfg.Candidates.Next() if err != nil { - // We've run out of addresses, double and clamp backoff. - backoff *= 2 - if backoff > n.cfg.MaxBackoff { - backoff = n.cfg.MaxBackoff + if backoff == 0 { + backoff = n.cfg.MinBackoff + } else { + // We've run out of addresses, double and clamp + // backoff. + backoff *= 2 + if backoff > n.cfg.MaxBackoff { + backoff = n.cfg.MaxBackoff + } } log.Debugf("Unable to get new tower candidate, "+