From 0690c8f627c4c87fdf59160b3077fb0dceb81373 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 4 Jul 2019 10:54:28 -0700 Subject: [PATCH] watchtower/wtclient: only reset iterator once we've exhausted all candidates Doing so allows us to load balance sessions better amongst all of the tower candidates. --- watchtower/wtclient/session_negotiator.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/watchtower/wtclient/session_negotiator.go b/watchtower/wtclient/session_negotiator.go index 9f92ee0a..e6ccbfb9 100644 --- a/watchtower/wtclient/session_negotiator.go +++ b/watchtower/wtclient/session_negotiator.go @@ -240,9 +240,6 @@ retryWithBackoff: } } - // Before attempting a bout of session negotiation, reset the candidate - // iterator to ensure the results are fresh. - n.cfg.Candidates.Reset() for { select { case <-n.quit: @@ -267,6 +264,13 @@ retryWithBackoff: log.Debugf("Unable to get new tower candidate, "+ "retrying after %v -- reason: %v", backoff, err) + // Only reset the iterator once we've exhausted all + // candidates. Doing so allows us to load balance + // sessions better amongst all of the tower candidates. + if err == ErrTowerCandidatesExhausted { + n.cfg.Candidates.Reset() + } + goto retryWithBackoff }