Backoff calculation throws ArithmeticException after many iterations
chringwer opened this issue · comments
In case of a repeat with an exponential backoff the next delay will always be calculated based on the current iteration no matter which maximum value has been set.
After 63 iterations or less (depending on the initial value and factor) that will result in the following exception:
java.lang.ArithmeticException: Exceeds capacity of Duration: 9223372036854775808000000000
at java.time.Duration.create(Duration.java:1006) ~[?:1.8.0_162]
at java.time.Duration.multipliedBy(Duration.java:963) ~[?:1.8.0_162]
at reactor.retry.Backoff$3.apply(Backoff.java:94) ~[reactor-extra-3.1.6.RELEASE.jar:3.1.6.RELEASE]
at reactor.retry.Backoff$3.apply(Backoff.java:91) ~[reactor-extra-3.1.6.RELEASE.jar:3.1.6.RELEASE]
at reactor.retry.AbstractRetry.calculateBackoff(AbstractRetry.java:68) ~[reactor-extra-3.1.6.RELEASE.jar:3.1.6.RELEASE]
at reactor.retry.DefaultRepeat.repeatBackoff(DefaultRepeat.java:113) ~[reactor-extra-3.1.6.RELEASE.jar:3.1.6.RELEASE]
at reactor.retry.DefaultRepeat.lambda$apply$1(DefaultRepeat.java:106) ~[reactor-extra-3.1.6.RELEASE.jar:3.1.6.RELEASE]
Once the current value is greater than max we should just set nextBackoff
to maxBackoff
and skip the computation.
Thanks for the report @chringwer. Would you be willing to try a PR against the 3.1.x
branch?
In reactor/reactor-core#1122 I introduced an operator directly in core that does exponential backoff. It is most probably suffering from the same issue so I'll need to investigate that.
PR #166 fixes the issue. Core has been verified and is ok.