当前位置:网站首页>webflux - webclient Connect reset by peer Error
webflux - webclient Connect reset by peer Error
2022-07-07 21:52:00 【iiaythi】
webflux - webclient Connect reset by peer
Error
Connect reset by peer 问题
Connection reset by peer
就是服务端在对端 Socket
连接关闭后仍然向其传输数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
一些常见的 socket 问题
异常 | 原因 |
---|---|
java.net.BindException:Address already in use: JVM_Bind | 该异常发生在服务器端进行new ServerSocket(port) 操作时,原因是本地端口已经被其他程序占用。此时用netstat –an 命令,可以看到本地已在使用状态的端口, 使用一个没有被占用的端口就能解决这个问题 |
java.net.ConnectException: Connection refused: connect | 该异常发生在客户端进行 new Socket(ip, port) 操作时,原因是无法找到目标 ip 地址的服务端(也就是从当前机器不存在到指定 ip 的路由),或者是该 ip 存在,但目标服务器上指定的端口没有程序监听 |
java.net.SocketException: Socket is closed | 该异常在客户端和服务器均可能发生,原因是己方主动关闭了连接后(调用了 Socket#close() 方法)再对网络连接进行读写操作 |
java.net.SocketException: Connect reset by peer | 另一个是,TCP 两端已经互发 FIN 报文正常关闭连接,但其中一端仍然使用该连接读写数据 |
java.net.SocketException: Connection reset | 当前端的 Socket 收到对端的 RST 报文后仍然读数据 |
java.net.SocketException: Broken pipe | 该异常在客户端和服务器均有可能发生,当前端在读写数据前断开连接(如当前端的程序准备写入数据到 Socket,结果发起IO调用后程序异常退出),则抛出该异常 |
网上原因
- reactor-netty 连接池分配了线程reactor-http-epoll-1处理一个请求A,reactor-http-epoll-1处理过程中因为慢 SQL 一直阻塞了 60s,在此期间同一个接口被高频率访问,连接池中的其他线程也被分配来处理同一类请求,然后也因为慢 SQL 阻塞住。在连接池中的线程都被阻塞住的时候,新的请求过来,连接池中已经没有线程可以对其进行处理,请求端因此一直被 hold,直到超时后主动关闭了 Socket。这之后服务端连接池线程终于处理完慢 SQL 请求,再来处理积压的请求,完成后把数据发送往请求端,却发现连接已经被关闭,就报出了Connection reset by peer 错误。本次排查得到的经验是,如果服务报出 Connection reset by peer 错误,首先检查是不是服务中有执行特别慢的动作阻塞了线程
- 文章地址: connect reset by peer
解决方案
设成短连接
public WebClient client() { if (webClient == null) { synchronized (lock) { if (webClient == null) { ClientHttpConnector connector = new ReactorClientHttpConnector(HttpClient.create().keepAlive(false)); webClient = WebClient.builder().clientConnector(connector).baseUrl("svc-user").build(); } } } return webClient; }
设置超时时间
ConnectionProvider provider = ConnectionProvider.builder("fixed") .maxConnections(500) .maxIdleTime(Duration.ofSeconds(20)) .maxLifeTime(Duration.ofSeconds(60)) .pendingAcquireTimeout(Duration.ofSeconds(60)) .evictInBackground(Duration.ofSeconds(120)).build(); this.webClient = WebClient.builder() .clientConnector(new ReactorClientHttpConnector(HttpClient.create(provider))) .build();
Connect reset 问题
Connection reset 就是服务端在对端
Socket` 连接关闭后仍然向其读数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
边栏推荐
- Display the server hard disk image to the browser through Servlet
- B_QuRT_User_Guide(40)
- Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
- B_QuRT_User_Guide(38)
- B_ QuRT_ User_ Guide(36)
- 产业共融新势能,城链科技数字峰会厦门站成功举办
- LM12丨Rolling Heikin Ashi二重K线滤波器
- Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
- B_ QuRT_ User_ Guide(37)
- 2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
猜你喜欢
UE4_ Ue5 panoramic camera
Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
B_QuRT_User_Guide(37)
SAP HR family member information
List. How to achieve ascending and descending sort() 2020.8.6
Matlab SEIR infectious disease model prediction
SAP HR奖罚信息导出
SAP HR reward and punishment information export
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
Ora-02437 failed to verify the primary key violation
随机推荐
JNI uses asan to check memory leaks
Extract the file name under the folder under win
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
B_QuRT_User_Guide(39)
How can we make money by making video clips from our media?
SAP HR social work experience 0023
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
USB (XV) 2022-04-14
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
B_QuRT_User_Guide(40)
Three questions TDM
Illegal behavior analysis 1
Right click the idea file to create new. There is no solution to create new servlet
Entity层、DAO层、Service层、Controller层 先后顺序
【7.4】25. K 个一组翻转链表
C method question 1
USB (XIV) 2022-04-12
Have all the fresh students of 2022 found jobs? Is it OK to be we media?