当前位置:网站首页>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` 连接关闭后仍然向其读数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
边栏推荐
- 【7.4】25. K 个一组翻转链表
- B_ QuRT_ User_ Guide(37)
- 2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
- Extended tree (I) - graphic analysis and C language implementation
- USB (XIV) 2022-04-12
- Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
- B_ QuRT_ User_ Guide(39)
- 【7.5】15. Sum of three numbers
- KeePass realizes automatic input of web pages
- Deep understanding of MySQL lock and transaction isolation level
猜你喜欢
List. How to achieve ascending and descending sort() 2020.8.6
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
How to change the formula picture in the paper directly into the formula in word
MongoDB快速入门
C method question 1
Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer
One week learning summary of STL Standard Template Library
SAP HR 社会工作经历 0023
B_QuRT_User_Guide(38)
Installing gradle
随机推荐
【汇总】看过的一些Panel与视频
Live-Server使用
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
B_QuRT_User_Guide(39)
USB (XIV) 2022-04-12
JNI uses asan to check memory leaks
B_QuRT_User_Guide(40)
StringUtils工具类
Given an array, such as [7864, 284, 347, 7732, 8498], now you need to splice the numbers in the array to return the "largest possible number."
postgis学习
Unity3d learning notes 5 - create sub mesh
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
Anxinco EC series modules are connected to the multi protocol access products of onenet Internet of things open platform
B / Qurt Utilisateur Guide (36)
HDU 4747 Mex「建议收藏」
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
Idea automatically generates serialVersionUID
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
[compilation principle] lexical analysis design and Implementation