当前位置:网站首页>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` 连接关闭后仍然向其读数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
边栏推荐
- Dependency injection 2 advantage lifecycle
- Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer
- [compilation principle] lexical analysis design and Implementation
- PCB wiring rules of PCI Express interface
- 【实验分享】通过Console口登录到Cisco设备
- windows设置redis开启自动启动
- The 19th Zhejiang Provincial College Programming Contest VP record + supplementary questions
- Deep understanding of MySQL lock and transaction isolation level
- 给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
- B_QuRT_User_Guide(39)
猜你喜欢

Oracle database backup and recovery

包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

2022第六季完美童模陕西总决赛圆满落幕

电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级

MySQL Index Optimization Practice I

SAP memory parameter tuning process

S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
![给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」](/img/21/2e99dd6173ab4925ec22290cd4a357.png)
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」

B / Qurt Utilisateur Guide (36)
随机推荐
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
648. Word replacement
HDU 4747 Mex「建议收藏」
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
Spark 离线开发框架设计与实现
2021icpc Shanghai h.life is a game Kruskal reconstruction tree
SLAM面试总结
进度播报|广州地铁七号线全线29台盾构机全部完成始发
MySQL Index Optimization Practice II
B_ QuRT_ User_ Guide(40)
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
How to login and enable synchronization function in Google browser
How can we make money by making video clips from our media?
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
【实验分享】通过Console口登录到Cisco设备
Illegal behavior analysis 1
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
Explain