当前位置:网站首页>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` 连接关闭后仍然向其读数据引起的,但是对端关闭连接的原因却是未知
可发生在客户端和服务器端
边栏推荐
- Ora-01741 and ora-01704
- SQL database execution problems
- 做自媒体视频剪辑怎么赚钱呢?
- [untitled]
- C method question 2
- 生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
- Summary of common methods of object class (September 14, 2020)
- Oracle database backup and recovery
- SAP HR reward and punishment information export
- Design and implementation of spark offline development framework
猜你喜欢

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

Map operation execution process

0-1背包问题

Summary of SQL single table query 2020.7.27

Spark 离线开发框架设计与实现

SAP memory parameter tuning process
![[compilation principle] lexical analysis design and Implementation](/img/8c/a3a50e6b029c49caf0d791f7d4513a.png)
[compilation principle] lexical analysis design and Implementation

USB (XV) 2022-04-14

UE4_ Ue5 combined with Logitech handle (F710) use record

C simple question one
随机推荐
ASP. Net core middleware request processing pipeline
Idea automatically generates serialVersionUID
【7.5】15. Sum of three numbers
USB (XVII) 2022-04-15
Matlab SEIR infectious disease model prediction
Three questions TDM
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
Fibonacci number of dynamic programming
Unity3d learning notes 5 - create sub mesh
Oracle statistics by time
ESP at installation esp8266 and esp32 versions
Interface
SAP HR reward and punishment information export
System design overview
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
ASP. Net open web page
[compilation principle] lexical analysis design and Implementation
做自媒体视频剪辑怎么赚钱呢?
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
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."