From 119079d7b9868f08dd96a863718ce8ce8b85d0fa Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Thu, 30 Aug 2018 22:56:38 +0000 Subject: [PATCH] backoff: avoid Timer.Reset() problems; honor minWait promise --- api/v1/lib/backoff/backoff.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/v1/lib/backoff/backoff.go b/api/v1/lib/backoff/backoff.go index 3993829a..aaf7ae19 100644 --- a/api/v1/lib/backoff/backoff.go +++ b/api/v1/lib/backoff/backoff.go @@ -72,6 +72,10 @@ func Notifier(minWait, maxWait time.Duration, until <-chan struct{}) <-chan stru d = maxWait } limiter = nil + // drain the timer to avoid Reset problems + if !t.Stop() { + <-t.C + } case <-t.C: if limiter != nil { d /= 2 @@ -82,7 +86,7 @@ func Notifier(minWait, maxWait time.Duration, until <-chan struct{}) <-chan stru return } // important to have non-zero minWait otherwise we busy-loop - if d == 0 { + if d < minWait { d = minWait } t.Reset(d)