35

My application is getting below error when consuming a service that performs queries in SQL Server using FeignClient.

ERROR:

Exception in thread "pool-10-thread-14" feign.RetryableException: Read timed out executing GET http://127.0.0.1:8876/processoData/search/buscaProcessoPorCliente?cliente=ELEKTRO+-+TRABALHISTA&estado=SP

My Consumer Service:

@FeignClient(url="http://127.0.0.1:8876")
public interface ProcessoConsumer {

@RequestMapping(method = RequestMethod.GET, value = "/processoData/search/buscaProcessoPorCliente?cliente={cliente}&estado={estado}")
public PagedResources<ProcessoDTO> buscaProcessoClienteEstado(@PathVariable("cliente") String cliente, @PathVariable("estado") String estado);

}

My YML:

server:
  port: 8874

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

eureka:
  client:
  serviceUrl:
    defaultZone: ${vcap.services.eureka-service.credentials.uri:http://xxx.xx.xxx.xx:8764}/eureka/
  instance: 
    preferIpAddress: true

ribbon:
  eureka:
    enabled: true

spring:
  application:
    name: MyApplication
  data:
    mongodb:
      host: xxx.xx.xxx.xx
      port: 27017
      uri: mongodb://xxx.xx.xxx.xx/recortesExtrator
      repositories.enabled: true
    solr:
      host: http://xxx.xx.xxx.xx:8983/solr
      repositories.enabled: true

Anyone know how to solve this?

Thanks.

daniel.eichten
  • 2,535
  • 19
  • 26
Renan Lalier
  • 671
  • 2
  • 7
  • 13

10 Answers10

52

Add the following properties into application.properties file, in milliseconds.

feign.client.config.default.connectTimeout=160000000
feign.client.config.default.readTimeout=160000000
Pavel Vlasov
  • 4,206
  • 6
  • 41
  • 54
chaitanya dalvi
  • 1,539
  • 2
  • 17
  • 25
  • 2
    Having tried all sort of black magic with properties consisting of Hystrix, ribbon and what not, this is the cleanest (and working) solution that I have encountered. – Abhishek Prabhat Aug 31 '19 at 05:46
  • 14
    The catch is that both need to be set for either of them to take effect. ‍♂️ Here's the relevant [source](https://github.com/spring-cloud/spring-cloud-openfeign/blob/21a2a59461f95fc1c78bd26a6f55187cc576c617/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java#L171) – kadam Sep 05 '19 at 00:59
  • 3
    I experimented the same issue, fixing the timeout only after setting both properties. An additional tip, you can configure different timeouts to different APIs replacing the _default_ word for the API feignName as described [here](https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html#spring-cloud-feign-overriding-defaults) – dbaltor Jul 08 '20 at 09:01
14

I'm using Feign.builder() to instantiate my Feign clients.

In order to set connectTimeout and readTimeout, I use the following :

Feign.builder()
     ...
     .options(new Request.Options(connectTimeout, readTimeout))
     .target(MyApiInterface.class, url);

Using this I can configure different timeout for different APIs.

yunandtidus
  • 3,847
  • 3
  • 29
  • 42
  • 3
    this .options is now deprecated, better use the new one .options(new Request.Options(CONNECTION_TIME_OUT_IN_SEC, TimeUnit.SECONDS,CONNECTION_TIME_OUT_IN_SEC, TimeUnit.Seconds, true)). The last param is for followRedirects. You can give any timeout value based on the unit provided. – im_bhatman Aug 05 '20 at 13:03
9

just ran into this issue as well. As suggested by @spencergibb here is the workaround I'm using. See the link

Add these in the application.properties.

# Disable Hystrix timeout globally (for all services)
hystrix.command.default.execution.timeout.enabled: false

# Increase the Hystrix timeout to 60s (globally)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000

Add this in the Java configuration class.

import feign.Request;

@Configuration
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { ServiceFeignClient.class })
@ComponentScan(basePackageClasses = { ServiceFeignClient.class })
public class FeignConfig {

    /**
     * Method to create a bean to increase the timeout value, 
     * It is used to overcome the Retryable exception while invoking the feign client.
     * @param env,
     *            An {@link ConfigurableEnvironment}
     * @return A {@link Request}
     */
    @Bean
    public static Request.Options requestOptions(ConfigurableEnvironment env) {
        int ribbonReadTimeout = env.getProperty("ribbon.ReadTimeout", int.class, 70000);
        int ribbonConnectionTimeout = env.getProperty("ribbon.ConnectTimeout", int.class, 60000);

        return new Request.Options(ribbonConnectionTimeout, ribbonReadTimeout);
    }
}
Sudhakar
  • 3,104
  • 2
  • 27
  • 36
  • 1
    Thanks. I don't use Hystrix, and all other suggestions to use ribbon.Read and Connect Timeout didn't work for me. But adding this bean solved it. – Vuk Djapic Apr 17 '18 at 09:31
2
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

make sure ribbon's timeout is bigger than hystrix

stayfool
  • 43
  • 4
  • 10
    That should be exactly vice versa: "When using Hystrix commands that wrap Ribbon clients you want to make sure your Hystrix timeout is configured to be longer than the configured Ribbon timeout, including any potential retries that might be made. For example, if your Ribbon connection timeout is one second and the Ribbon client might retry the request three times, than your Hystrix timeout should be slightly more than three seconds." https://cloud.spring.io/spring-cloud-netflix/single/spring-cloud-netflix.html#_hystrix_timeouts_and_ribbon_clients – Alexander Palamarchuk Dec 20 '17 at 16:05
  • Updated link to @AlexanderPalamarchuk comment's source: https://cloud.spring.io/spring-cloud-netflix/multi/multi__hystrix_timeouts_and_ribbon_clients.html – dbaltor Jul 13 '20 at 09:45
2

For those who use spring-cloud-starter-openfeign:

spring.cloud.openfeign.client.config.default.readTimeout=5000 spring.cloud.openfeign.client.config.default.connect-timeout=5000

Evgeniy Averkin
  • 311
  • 3
  • 2
1

You can add 'Options' argument to you methods and control timeouts dynamically.

@FeignClient(url="http://127.0.0.1:8876")
public interface ProcessoConsumer {
    @RequestMapping(method = RequestMethod.GET, value = "/processoData/search/buscaProcessoPorCliente?cliente={cliente}&estado={estado}")
    PagedResources<ProcessoDTO> buscaProcessoClienteEstado(@PathVariable("cliente") String cliente, @PathVariable("estado") String estado,
                                                                  Request.Options options);
}

Use like next:

processoConsumer.buscaProcessoClienteEstado(..., new Request.Options(100, TimeUnit.MILLISECONDS,
        100, TimeUnit.MILLISECONDS, true));
E.H.
  • 326
  • 1
  • 7
0

Add the below properties to the application.properties file

value 5000 is in milliseconds

feign.client.config.default.connectTimeout: 5000
feign.client.config.default.readTimeout: 5000
Uttam Pawar
  • 104
  • 7
-2

Look at this answer. It did the trick for me. I also did a bit of research and I've found the properties documentation here:

https://github.com/Netflix/Hystrix/wiki/Configuration#intro

Community
  • 1
  • 1
Marco Tedone
  • 592
  • 4
  • 13
-3

eureka: client: eureka-server-read-timeout-seconds: 30

-4

Add these in the application.properties

feign.hystrix.enabled=false hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000

Community
  • 1
  • 1
chen
  • 1