Connection reset by peer原理解析

“Connection reset by peer”代表什么?
“Connection reset by peer”表示当前服务器接受到了通信对端发送的TCP RST信号,即通信对端已经关闭了连接,通过RST信号希望接收方关闭连接。

The remote server has sent you a RST packet, which indicates an immediate dropping of the connection, rather than the usual handshake. This bypasses the normal half-closed state transition.

产生RST场景或者导致“Connection reset by peer”场景?

1.当尝试和未开放的服务器端口建立tcp连接时,服务器tcp将会直接向客户端发送reset报文;
2.双方之前已经正常建立了通信通道,也可能进行过了交互,当某一方在交互的过程中发生了异常,如崩溃等,异常的一方会向对端发送reset报文,通知对方将连接关闭;
3.当收到TCP报文,但是发现该报文不是已建立的TCP连接列表可处理的,则其直接向对端发送reset报文;
4.ack报文丢失,并且超出一定的重传次数或时间后,会主动向对端发送reset报文释放该TCP连接;

参考:

https://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean;
http://lovestblog.cn/blog/2014/05/20/tcp-broken-pipe/;

原文地址:https://www.cnblogs.com/toSeeMyDream/p/9890024.html