Fix potentially loses precision and jitter is not well capped with unit tests

Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>
This commit is contained in:
NeatGuyCoding
2025-07-01 10:56:53 +02:00
committed by Juergen Hoeller
parent eeedeb3b10
commit 009b880e92
2 changed files with 162 additions and 1 deletions
@@ -136,7 +136,10 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
Publisher<?> publisher = adapter.toPublisher(result);
Retry retry = Retry.backoff(spec.maxAttempts(), spec.delay())
.jitter((double) spec.jitter().toMillis() / spec.delay().toMillis())
.jitter(
spec.delay().isZero() ? 0.0 :
Math.max(0.0, Math.min(1.0, spec.jitter().toNanos() / (double) spec.delay().toNanos()))
)
.multiplier(spec.multiplier())
.maxBackoff(spec.maxDelay())
.filter(spec.combinedPredicate().forMethod(method));