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

@Retryable annotation retrying with ExponentialBackOff instead of ExponentialRandomBackOff when randomExpression provided #427

Closed
aftabshk opened this issue Apr 27, 2024 · 1 comment
Labels
Milestone

Comments

@aftabshk
Copy link
Contributor

aftabshk commented Apr 27, 2024

I am using following versions:

Java - 17
Spring Retry - 2.0.5
Spring Boot - 3.2.5
Example code to reproduce issue: spring-retry-issue

When I am using the @retryable annotation like following on any method:

@Retryable(retryFor = {RuntimeException.class}, maxAttempts = 10, backoff = @Backoff(delay = 2000, multiplier = 2, random = true))

Everything works as expected. I get 10 retries exponentially, increasing and with randomness in time. But, when I use the exact same values but pass them via application.properties as follows:

@Retryable(retryFor = {RuntimeException.class}, maxAttemptsExpression = "${retry.max-attempts}", backoff = @Backoff(delayExpression = "${retry.delay}", multiplierExpression = "${retry.multiplier}", randomExpression = "${retry.random}"))

Then I get 10 retries but only exponentially increasing and no randomness in time

You can see the example code here: spring-retry-issue

I have identified the issue in the code of the spring-retry library and raised a corresponding Pull Request for the same.
Here it is: Pull request 428
Please have a look and let me know if this works.

@gaofengIt
Copy link

gaofengIt commented Apr 27, 2024 via email

aftabshk added a commit to aftabshk/spring-retry that referenced this issue Apr 27, 2024
@artembilan artembilan added the bug label Apr 29, 2024
@artembilan artembilan added this to the 2.0.6 milestone Apr 29, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 3, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 3, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 3, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 3, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 9, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 10, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 10, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 10, 2024
aftabshk added a commit to aftabshk/spring-retry that referenced this issue May 10, 2024
natedanner pushed a commit to natedanner/spring-projects__spring-retry that referenced this issue May 20, 2024
Fixes: spring-projects#427

No randomness with configuration like:
```
@retryable(retryFor = {RuntimeException.class}, maxAttemptsExpression = "${retry.max-attempts}", backoff = @backoff(delayExpression = "${retry.delay}", multiplierExpression = "${retry.multiplier}", randomExpression = "${retry.random}"))
```

The random logic in the `AnnotationAwareRetryOperationsInterceptor` if  `multiplierExpression` is for runtime evaluation.

* Fix `AnnotationAwareRetryOperationsInterceptor` to check for `if (multiplier > 0 || parsedMultExp != null) {` before evaluating `random`
* Fix `@BackOff(randomExpression)` Javadoc to indicate that it is always evaluated on configuration phase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants