-
Notifications
You must be signed in to change notification settings - Fork 307
Closed
Labels
Description
While building a network policy with high delay values I receive a long overflow exception.
java.lang.ArithmeticException: long overflow
at java.lang.Math.multiplyExact(Math.java:892)
at java.time.Duration.toNanos(Duration.java:1186)
at net.jodah.failsafe.RetryPolicy.withBackoff(RetryPolicy.java:394)
The code to replciate this may be something like this:
final RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.withBackoff(500, Integer.MAX_VALUE, ChronoUnit.MILLIS, 1.50)
It then tries to convert that to nanoseconds to compare the values which is causing the overflow.
public RetryPolicy<R> withBackoff(long delay, long maxDelay, ChronoUnit chronoUnit, double delayFactor) {
(...)
Duration delayDuration = Duration.of(delay, chronoUnit);
Duration maxDelayDuration = Duration.of(maxDelay, chronoUnit);
Assert.state(maxDuration == null || delayDuration.toNanos() < maxDuration.toNanos(),
"delay must be less than the maxDuration");
Assert.isTrue(delayDuration.toNanos() < maxDelayDuration.toNanos(), "delay must be less than the maxDelay");
(...)
return this;
}