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

时间:2025-04-08 10:54:51

问题介绍:

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

: Read timed out executing POST http://******
        at (:67)
        at (:104)
        at (:76)
        at $(:103)
        at .$(Unknown Source)
Caused by: : Read timed out
        at .socketRead0(Native Method)
        at (:116)
        at (:170)
        at (:141)
        at (:246)
        at .read1(:286)
        at (:345)
        at (:704)
        at (:647)
        at .getInputStream0(:1569)
        at (:1474)
        at (:480)
        at $(:152)
        at $(:74)

原因及解决办法:

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

#请求处理的超时时间
: 120000
#请求连接的超时时间
: 30000

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

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

: FeignDemo#demo() timed-out and no fallback available.
	at $(:819)
	at $(:804)
	at $(:140)
	at $(:87)
	at $(:87)
	at $DeprecatedOnFallbackHookApplication$(:1472)
	at $FallbackHookApplication$(:1397)
	at $(:87)
	at $(:230)
	Caused by: 
	at (:997)
	at $500(:60)
	at $(:610)
	at $(:601)

解决办法:


: true
hystrix 熔断机制
hystrix:
  shareSecurityContext: true
  command:
    default:
      circuitBreaker:
        sleepWindowInMilliseconds: 100000
        forceClosed: true
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 600000