From b1c53f4a84f29b5aec12910f23b9ae5c69c57228 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:26:43 +0900 Subject: [PATCH] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index a9b878db01..d0cc283497 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -121,7 +121,7 @@ func (b *backoff) Do( dctx, cancel := context.WithDeadline(sctx, time.Now().Add(b.backoffTimeLimit)) defer cancel() - for cnt := 1; cnt <= b.maxRetryCount; cnt++ { + for cnt := 0; cnt < b.maxRetryCount; cnt++ { select { case <-dctx.Done(): switch dctx.Err() { @@ -185,21 +185,19 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) - if cnt >= b.maxRetryCount { - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err - default: - return nil, errors.Join(dctx.Err(), err) - } + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err default: + return nil, errors.Join(dctx.Err(), err) } + default: } } }