feign.RetryableException: Read timed out executing POST xxx

avatar 2018年09月16日17:01:45 6 13425 views
博主分享免费Java教学视频,B站账号:Java刘哥 ,长期提供技术问题解决、项目定制:本站商品点此

问题介绍:


服务之间调用报错超时,截取部分报错,Read timed out executing POST http://******
  1. feign.RetryableException: Read timed out executing POST http://******
  2.         at feign.FeignException.errorExecuting(FeignException.java:67)
  3.         at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
  4.         at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
  5.         at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
  6.         at com.sun.proxy.$Proxy113.getBaseRow(Unknown Source)
  7. Caused by: java.net.SocketTimeoutException: Read timed out
  8.         at java.net.SocketInputStream.socketRead0(Native Method)
  9.         at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
  10.         at java.net.SocketInputStream.read(SocketInputStream.java:170)
  11.         at java.net.SocketInputStream.read(SocketInputStream.java:141)
  12.         at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
  13.         at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
  14.         at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
  15.         at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
  16.         at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
  17.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
  18.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
  19.         at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
  20.         at feign.Client$Default.convertResponse(Client.java:152)
  21.         at feign.Client$Default.execute(Client.java:74)


原因及解决办法:


明显可以看到是http请求报错超时,feign的调用分两层,ribbon的调用和hystrix的调用,高版本的hystrix默认是关闭的,所以在application.properties配置文件中设置ribbon即可
  1. ribbon:
  2.   ReadTimeout: 60000
  3.   ConnectTimeout: 60000
  4.   eureka:
  5.     enable: true



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

FeignDemo#demo() timed-out and no fallback available。和ribbon超时报错还是有区别的
  1. com.netflix.hystrix.exception.HystrixRuntimeException: FeignDemo#demo() timed-out and no fallback available.
  2.     at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
  3.     at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
  4.     at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
  5.     at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
  6.     at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
  7.     at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
  8.     at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
  9.     at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
  10.     at rx.observers.Subscribers$5.onError(Subscribers.java:230)
  11.     Caused by: java.util.concurrent.TimeoutException
  12.     at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:997)
  13.     at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:60)
  14.     at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:610)
  15.     at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:601)


解决办法:

  1. feign.hystrix.enabled: true
  2. hystrix 熔断机制
  3. hystrix:
  4.   shareSecurityContext: true
  5.   command:
  6.     default:
  7.       circuitBreaker:
  8.         sleepWindowInMilliseconds: 100000
  9.         forceClosed: true
  10.       execution:
  11.         isolation:
  12.           thread:
  13.             timeoutInMilliseconds: 600000



原文地址:https://blog.csdn.net/sayoko06/article/details/81329415



  • 微信
  • 交流学习,资料分享
  • weinxin
  • 个人淘宝
  • 店铺名:言曌博客咨询部

  • (部分商品未及时上架淘宝)
avatar

发表评论

avatar 登录者:匿名
匿名评论,评论回复后会有邮件通知

  

已通过评论:0   待审核评论数:0