Connection reset by peer异常解决办法
约几十个请求过去后,出现异常。
·
约几十个请求过去后,出现Caused by: java.io.IOException: Connection reset by peer异常
Caused by: java.io.IOException: Connection reset by peer
at java.base/sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at java.base/sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:62)
at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:132)
at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:97)
at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:53)
at java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:532)
at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:118)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1381)
at org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:764)
at org.apache.tomcat.util.net.SocketWrapperBase.writeBlocking(SocketWrapperBase.java:589)
at org.apache.tomcat.util.net.SocketWrapperBase.write(SocketWrapperBase.java:533)
at org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.doWrite(Http11OutputBuffer.java:540)
at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:84)
at org.apache.coyote.http11.Http11OutputBuffer.doWrite(Http11OutputBuffer.java:193)
at org.apache.coyote.Response.doWrite(Response.java:616)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:331)
... 87 common frames omitted
排查
根据网络上查询的结果,有以下几种常见情况
服务并发处理处理不过来,会关闭其中的一些连接
防火墙
客户端关闭了连接(未通知服务端四次挥手,例如直接关闭客户端)
经排查不属于以上情况,最后定位到open files设置的值调小了导致的
我使用的Centos7,默认打开文件数为1024个,通过ulimit -a 可以查看open files
[root@localhost docker]# ulimit -a | grep open
open files (-n) 1024
解决办法
1.修改ulimit
vim /etc/security/limits.conf
# 在最后追加以下内容
* soft nofile 65536
* hard nofile 65536
或者使用如下命令直接追加至 /etc/security/limits.conf 文件
echo "* soft nofile 65536
* hard nofile 65536 " >> /etc/security/limits.conf
检查是否生效
[root@localhost docker]# ulimit -a | grep open
open files (-n) 65536
2.重启后台服务
到此问题解决!
更多推荐


所有评论(0)