当前位置: 代码迷 >> 综合 >> spring cloud 调用feign请求超时 feign.RetryableException: Read timed out executing POST
  详细解决方案

spring cloud 调用feign请求超时 feign.RetryableException: Read timed out executing POST

热度:60   发布时间:2023-09-19 21:41:54.0

问题介绍:

服务之间调用报错超时,截取部分报错,Read timed out executing POST http://******

feign.RetryableException: Read timed out executing POST http://******

        at feign.FeignException.errorExecuting(FeignException.java:67)

        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)

        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)

        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)

        at com.sun.proxy.$Proxy113.getBaseRow(Unknown Source)

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

        at java.net.SocketInputStream.socketRead0(Native Method)

        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

        at java.net.SocketInputStream.read(SocketInputStream.java:170)

        at java.net.SocketInputStream.read(SocketInputStream.java:141)

        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)

        at java.io.BufferedInputStream.read(BufferedInputStream.java:345)

        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)

        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)

        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)

        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)

        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)

        at feign.Client$Default.convertResponse(Client.java:152)

        at feign.Client$Default.execute(Client.java:74)

原因及解决办法:

明显可以看到是http请求报错超时,feign的调用分两层,ribbon的调用和hystrix的调用,高版本的hystrix默认是关闭的,所以在application.properties配置文件中设置ribbon即可

#请求处理的超时时间

ribbon.ReadTimeout: 120000

#请求连接的超时时间

ribbon.ConnectTimeout: 30000

如果开启hystrix,hystrix的超时报错如下图:

 FeignDemo#demo() timed-out and no fallback available。和ribbon超时报错还是有区别的

com.netflix.hystrix.exception.HystrixRuntimeException: FeignDemo#demo() timed-out and no fallback available.

at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)

at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)

at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)

at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)

at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)

at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)

at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)

at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)

at rx.observers.Subscribers$5.onError(Subscribers.java:230)

Caused by: java.util.concurrent.TimeoutException

at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:997)

at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:60)

at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:610)

at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:601)

解决办法:

feign.hystrix.enabled: true

hystrix 熔断机制

hystrix:

shareSecurityContext: true

command:

default:

circuitBreaker:

sleepWindowInMilliseconds: 100000

forceClosed: true

execution:

isolation:

thread:

timeoutInMilliseconds: 600000

  相关解决方案