'Spring cloud - Zuul cannot set timeout

I have a zuul server with a config file as:

server:
  port: 9090
eureka:
  client:
    serviceUrl:
      defaultZone: http://172.16.5.147:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 30
    hostname: dev-zuulserver
    non-secure-port: 80
zuul:
          prefix: /v1
          sensitiveHeaders: Cookie, Set-Cookie
          ignoredHeaders: Access-Control-Allow-Origin
          host:
            connect-timeout-millis: 60000 # starting the connection
            socket-timeout-millis: 120000  # monitor the continuous incoming data flow
        ribbon:
          eureka:
            enabled: true
            ReadTimeout: 120000
            ConnectTimeout: 3000
        hystrix:
          command:
            default:
              execution:
                isolation:
                  strategy: THREAD
                  thread:
                    timeoutInMilliseconds: 60000

And I have some queries with longer timeout (more than one minute). But, all my requests always error out with a time out, request time always is less than 6000 ms.

And zuul show this exception:

Caused by: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out

at rx.exceptions.Exceptions.propagate(Exceptions.java:58) ~[rxjava-1.1.10.jar!/:1.1.10]
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:465) ~[rxjava-1.1.10.jar!/:1.1.10] at rx.observables.BlockingObservable.single(BlockingObservable.java:342) ~[rxjava-1.1.10.jar!/:1.1.10] at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:117) ~[ribbon-loadbalancer-2.2.2.jar!/:2.2.2] ... 133 common frames omitted Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_131] at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_131] at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_131] at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_131] at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165) ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.6.jar!/:4.4.6]

Does anyone have a solution for this case?

Thank you!



Solution 1:[1]

Try by adding timeout for Ribbon in ZUUL config.
Following will set timeout of 2min.

ribbon:
  ConnectTimeout: 120000
  ReadTimeout: 120000

Solution 2:[2]

In your application.properties just add:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 240000
ribbon.ConnectTimeout: 120000
ribbon.ReadTimeout: 120000

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bhushan
Solution 2 Johan David Munoz Olarte