From 6f6aafc9ac510a8daa876333273330e888870248 Mon Sep 17 00:00:00 2001 From: Danlock Date: Sat, 14 Oct 2023 11:42:58 -0400 Subject: [PATCH] internal.Retry takes into account the last delay for considering healthy lifetimes --- internal/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/util.go b/internal/util.go index ff1d3e8..a7429f1 100644 --- a/internal/util.go +++ b/internal/util.go @@ -58,7 +58,7 @@ func (l AMQP091Logger) Printf(format string, v ...interface{}) { const healthyLifetime = 20 * time.Millisecond // Retry attempts do repeatedly until it's ctx ends. If do returns false delayForAttempt is used to backoff retries. -// If do is true and ran longer than healthyLifetime the backoff is reset. do returns it's own lifetime, since it may do some setup beforehand. +// If do is true and ran longer than healthyLifetime or it's last delay the backoff is reset. do returns it's own lifetime, since it may do some setup beforehand. func Retry(ctx context.Context, delayForAttempt func(int) time.Duration, do func(time.Duration) (time.Duration, bool)) { var delay time.Duration var attempt = 0 @@ -66,7 +66,7 @@ func Retry(ctx context.Context, delayForAttempt func(int) time.Duration, do func delay = delayForAttempt(attempt) attempt++ lifetime, ok := do(delay) - if ok && lifetime >= healthyLifetime { + if ok && lifetime >= max(healthyLifetime, delay) { delay, attempt = 0, 0 }