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: } } }