出现场景:
线上发布时报错:
问题分析:
1、客户端请求服务器数据,服务器突然挂了;
2、客户端请求服务端数据,服务端正常返回,凡是客户端由于超时等原因断开。
解决Java中的java.io.IOException: Broken pipe问题 - CharyGao - 博客园 (cnblogs.com)
解决思路:扩大连接时间,设置超时时间
一、设置网关超时时间
spring:
cloud:
gateway:
httpclient:
connect-timeout: 1000000
response-timeout: 120s
二、设置openFeign调用超时时间
feign:
client:
config:
default:
# 日志级别
loggerLevel: full
# 超时设置 10秒超时
connectTimeout: 10000
readTimeout: 10000
三、设置http请求超时时间
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
.setConnectionRequestTimeout(35000)// 请求超时时间
.setSocketTimeout(60000)// 数据读取超时时间
.build();
// 为httpGet实例设置配置
httpPost.setConfig(requestConfig);