Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backoff calculation throws ArithmeticException after many iterations #164

Closed
chringwer opened this issue Aug 22, 2018 · 2 comments
Closed
Assignees
Labels
type/bug A general bug
Milestone

Comments

@chringwer
Copy link

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.

Duration nextBackoff = firstBackoff.multipliedBy((long) Math.pow(factor, (context.iteration() - 1)));

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.

@simonbasle simonbasle added the type/bug A general bug label Aug 22, 2018
@simonbasle simonbasle added this to the 3.1.x Maintenance Backlog milestone Aug 22, 2018
@simonbasle
Copy link
Member

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.

simonbasle added a commit that referenced this issue Aug 28, 2018
This commit avoids backoff duration growing too large by:
 1) not doing any computation if the current backoff is already equal to
 configured maxBackoff
 2) catching an `ArithmeticException` and setting the next backoff to
 maxBackoff in that case
@simonbasle simonbasle self-assigned this Aug 29, 2018
@simonbasle
Copy link
Member

PR #166 fixes the issue. Core has been verified and is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants