springspring-retry

Problem with exponential backoff in Spring Retry - delayExpression doesn't work with multiplierExpression


I'm trying to add retries to my calls using Spring Retry (newest version).

I've added the following annotation:

@Retryable( maxAttemptsExpression = "${retry.app.maxAttempts}",
            backoff = @Backoff(delayExpression = "${retry.app.backOffDelay}",
            multiplierExpression = "${retry.app.multiplier}"))
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AppRetryable {
}

and applied it to my HTTP client (Feign).

The values for retryable are defined in the following properties:

retry:
  app:
    multiplier: 2
    backOffDelay: 10000
    maxAttempts: 3

The problem is that while it generally works fine (the calls are being retried every 10s for 3 times) the time doesn't grow exponentially.

I've noticed that if replace delayExpression and multiplierExpression with delay and multiplier and add hardcoded values it works fine. What is more is that replacing just delayExpression also works fine.

In other words:

        backoff = @Backoff(delay = 10000,
        multiplier = 2))

works fine.

And this one is fine too:

        backoff = @Backoff(delay = 10000,
        multiplierExpression = "${retry.app.multiplier}"))

But not:

        backoff = @Backoff(delayExpression = "${retry.app.backOffDelay}",
        multiplierExpression = "${retry.app.multiplier}"))

Is there anything I'm doing wrong or there is a bug in the library?


Solution

  • There is a recent fix for this (not yet released).

    https://github.com/spring-projects/spring-retry/issues/397