spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
707 stars 703 forks source link

RetryLoadBalancerInterceptor does not allow to retry on specific exceptions #1043

Closed danparisi closed 2 years ago

danparisi commented 2 years ago

Is your feature request related to a problem? Please describe. I'd like to configure retries not by status code (as it's currently allowed), but by exceptions. For example I'd like the call to be retried in case of HttpHostConnectException or ConnectTimeoutException, etc.

Describe the solution you'd like I'd like to have a property that lets me configure the exception list (something similar is provided by Resilience4j), for example:

spring:
  cloud:
    loadbalancer:
      retry:
        retryableExceptions:
          - org.apache.http.conn.ConnectTimeoutException
          - java.net.ConnectException
          - java.net.UnknownHostException

Describe alternatives you've considered Maybe I could wrap the call with some other library that allows this feature, like spring-retry or resilience4j but I guess it won't work properly because - for example - the last instance won't be filtered and such retry could hit the same (broken) one.

OlgaMaciaszek commented 2 years ago

Hello, @danparisi. With LB retries, we assume that we do get a response before a retry. In the case you're describing, we would not be getting a response at all. It should be quite easy to implement. Will discuss this with the team and get back to you.

spencergibb commented 2 years ago

Gateway does this already in it's filter

danparisi commented 2 years ago

@spencergibb yes but to be honest I'd like to ask for a feature request for the gateway too, you can find it https://github.com/spring-cloud/spring-cloud-gateway/issues/2543. Sorry for the off topic :)