spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Add backoff support to Retry filter in Spring Cloud Gateway MVC (server-mvc)

Open tfactor2 opened this issue 7 months ago • 8 comments

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)

tfactor2 avatar Apr 09 '26 09:04 tfactor2

Would you be interested in creating a PR to add this?

ryanjbaxter avatar Apr 09 '26 13:04 ryanjbaxter

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. )

JoeCqupt avatar Apr 23 '26 14:04 JoeCqupt

@ryanjbaxter, we decided to move to our custom implementation based on okhttpclient. For now unfortunately not.

tfactor2 avatar Apr 23 '26 14:04 tfactor2

@JoeCqupt we would have to support all of them IMO

ryanjbaxter avatar Apr 23 '26 14:04 ryanjbaxter

Hi @JoeCqupt — are you still planning to work on this? If not, I'd like to pick it up. Thanks!

celikfatih avatar May 13 '26 18:05 celikfatih

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 avatar May 14 '26 01:05 JoeCqupt

@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.

goutamadwant avatar Jun 26 '26 06:06 goutamadwant

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!

treasure-haenaryn avatar Jul 06 '26 07:07 treasure-haenaryn