From 48e045289e1c82f18c0db3b4d89c51cc1a739081 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:03:35 +0900 Subject: [PATCH] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index d0cc283497..b1407c30d2 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -185,19 +185,21 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) - 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 + 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) + } default: - return nil, errors.Join(dctx.Err(), err) } - default: } } }