feign icon indicating copy to clipboard operation
feign copied to clipboard

Unable to override default timeout for hystrix.

Open Arunkayathi opened this issue 4 years ago • 3 comments

I am using combination of (open-feign) and (feign-hystrix) to communicate with another micro service. For some requests, It's taking longer(3s) to get a response and as a result I am getting hystrix runtime exception saying "getting timed out and no fall back available". So inorder to bump up the timeout I have added the following property in the yml file

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 10000

But feign is not considering the timeout mentioned in the yml file. I have also tried using the Request.options but was unsuccessful in that as well. Is there any configuration that I have to do to override the default timeout?

@Builder
public class FeignBasicConfig {

    Builder baseFeignConfig() {
        return HystrixFeign.builder()
                           .encoder(new JacksonEncoder(objectMapper))
                           .decoder(new JacksonDecoder(objectMapper))
                           .options(new Options(5000L, TimeUnit.MILLISECONDS, 5000L, TimeUnit.MILLISECONDS, false))
                           .retryer(new Retryer.Default(200, SECONDS.toMillis(5), 5));
    }
}


@Configuration
@RequiredArgsConstructor
public class UsersClientConfig {

    private final FeignConfig feignConfig;
    
    @Bean
    public UsersClient usersClient(
          @Value("${services.usersClient.baseUrl:#{null}}") String url,
          @Value("${services.usersClient.username:#{null}}") String username,
          @Value("${services.usersClient.password:#{null}}") String password) {

     
        return feignConfig
              .baseFeignConfig()
              .requestInterceptor(new BasicAuthRequestInterceptor(username,password))
              .target(UsersClient.class, url);
    }
}
public interface UsersClient {

    @RequestLine("GET /users/{userId}")
    CompletableFuture<UsersClientDto> getUserById(@Param("userId") String userId);
}

Arunkayathi avatar Jul 22 '20 15:07 Arunkayathi

Our Options object does not apply to Hystrix specific timeouts at the command group level. You will need to configure them directly in the Hystrix Configuration. In this case you need to consider additional settings to get what you need. Look at the Thread Pool documentation for Hystrix for more information.

Also, I recommend not using our Options if you are using Hystrix. They will conflict.

kdavisk6 avatar Sep 18 '20 21:09 kdavisk6

I needed to set up timeouts for Hystrix too and documented my findings on StackOverflow.

jaredpetersen avatar Sep 15 '21 20:09 jaredpetersen

The Hystrix configuration integration has always left something to be desired, due to the nature of Hystrix and how it defines capabilities at the command key level. Good find. I'll update our documentation with your findings.

kdavisk6 avatar Oct 06 '21 14:10 kdavisk6