spring-projects / spring-retry

2.15k stars 514 forks source link

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

Closed aftabshk closed 4 months ago

aftabshk commented 4 months ago

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 commented 4 months ago

您好,我已经收到您的邮件,将尽快给您回复。