From cdfdfc352936d4ae330271009d2af52fed373e00 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Mon, 9 Sep 2024 11:04:36 +0900 Subject: [PATCH] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 2d7860b120..0c30f6571e 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -186,23 +186,25 @@ func (b *backoff) Do( dur *= b.backoffFactor jdur = b.addJitter(dur) } + if cnt >= b.maxRetryCount-1 { + 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: + } + } } } } - 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 res, err }