Add backoff support to Retry filter in Spring Cloud Gateway MVC (server-mvc)
The RetryFilterFunctions.RetryConfig class in the spring-cloud-gateway-server-webmvc module does not support backoff configuration, while the reactive (WebFlux) variant (RetryGatewayFilterFactory) does.
Current state
Neither of the two current MVC retry implementations supports backoff:
GatewayRetryFilterFunctions— Spring Retry-based, deprecated (Spring Retry is in maintenance-only mode)FrameworkRetryFilterFunctions— Spring Framework retry-based, the new preferred path
Neither exposes a backoff option, and RetryConfig has no backoff field or setter.
This was previously noted with a // TODO: backoff comment in the old RetryFilterFunctions before the refactoring.
Expected behavior
RetryConfig should support backoff configuration equivalent to what the reactive module offers via RetryGatewayFilterFactory, e.g.:
.filter(retry(config -> {
config.setRetries(3);
config.setBackoff(Duration.ofMillis(100), Duration.ofMillis(500), 2, false);
}))
And YAML parity with the reactive module:
filters:
- name: Retry
args:
retries: 3
backoff:
firstBackoff: 100ms
maxBackoff: 500ms
factor: 2
basedOnPreviousValue: false
Version
spring-cloud-gateway-server-webmvc — main branch (post-refactoring to FrameworkRetryFilterFunctions)
Would you be interested in creating a PR to add this?
Would you be interested in creating a PR to add this?
@ryanjbaxter I'd like to solve this issue, but some solutions need confirmation:
- GatewayRetryFilterFunctions using SpringRetry.
- FrameworkRetryFilterFunctions using Spring Framework Retry.
- RetryGatewayFilterFactory using Reactor Retry. The backoff and jitter parameters for these retry methods are not entirely the same; Can we tolerate these parameter differences?(some parameters are supported while others are not. )
@ryanjbaxter, we decided to move to our custom implementation based on okhttpclient. For now unfortunately not.
@JoeCqupt we would have to support all of them IMO
Hi @JoeCqupt — are you still planning to work on this? If not, I'd like to pick it up. Thanks!
Hi @JoeCqupt — are you still planning to work on this? If not, I'd like to pick it up. Thanks!
I have no idea about this issue. You can pick it up
@JoeCqupt @ryanjbaxter I opened a PR for this. It adds MVC retry backoff support for both retry implementations and includes coverage for both paths plus nested backoff config binding. Let me know if you have any suggestions.
The lack of WebMVC retry backoff is a big pain point since immediate 0-second retries heavily stress our downstream services. Now that recent Java versions have beautifully resolved the carrier thread pinning issue, adding backoff would make it perfect. So grateful that you are reviewing and bringing this native support to life!