当前位置:网站首页>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` 连接关闭后仍然向其读数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
边栏推荐
- Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
- Happy gathering time
- Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
- 648. Word replacement
- Force deduction solution summary 648 word replacement
- The file format and extension of XLS do not match
- [compilation principle] lexical analysis design and Implementation
- Flash encryption process and implementation of esp32
- 进度播报|广州地铁七号线全线29台盾构机全部完成始发
- Extended tree (I) - graphic analysis and C language implementation
猜你喜欢

C inheritance and interface design polymorphism

Ora-02437 failed to verify the primary key violation
![Given an array, such as [7864, 284, 347, 7732, 8498], now you need to splice the numbers in the array to return the](/img/21/2e99dd6173ab4925ec22290cd4a357.png)
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."

Three questions TDM

First week of July

SAP HR family member information

Design and implementation of spark offline development framework

What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method

LM12丨Rolling Heikin Ashi二重K线滤波器

包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
随机推荐
SQL database execution problems
HDU 4747 Mex「建议收藏」
Understand TCP's three handshakes and four waves with love
产业共融新势能,城链科技数字峰会厦门站成功举办
Class C design questions
Access database query all tables SQL
sql 数据库执行问题
ESP at installation esp8266 and esp32 versions
Happy gathering time
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
The file format and extension of XLS do not match
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
通达信买基金安全吗?
C method question 1
Three questions TDM
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
IDEA 2021.3. X cracking
Interface
postgis学习
StringUtils工具类