ChatGPT解决这个技术问题 Extra ChatGPT

What does "connection reset by peer" mean?

What is the meaning of the "connection reset by peer" error on a TCP connection? Is it a fatal error or just a notification or related to the network failure?


u
user207421

It's fatal. 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. I like this description:

"Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook. It's more polite than merely not replying, leaving one hanging. But it's not the FIN-ACK expected of the truly polite TCP/IP converseur.


Why is it labelled "connection reset by peer”? It sounds like it should be "connection reset by the host", or "connection reset by the server"
@Robert Because that's where the reset came from. The peer sent an RST packet.
... Robert, your concern makes no sense to me. Peer is just strictly more general than that. In a typical client-server model, the server can just as easily receive this notification from the "client". The machine that initially requests the connection has just as much power to send this notification. On a TCP level, it looks identical once the connection is ongoing. The two machines, when communicating, are just peers.
This packed could have been sent by another device in the middle like a router?
It cannot be called 'connection reset by server' because it can be sent by the client or the server. It cannot be 'bypassed'. If a client receives this error this means the TCP connection is no longer open in the server, for example since the server crashed and was restarted.
C
Chris Huang-Leaver

This means that a TCP RST was received and the connection is now closed. This occurs when a packet is sent from your end of the connection but the other end does not recognize the connection; it will send back a packet with the RST bit set in order to forcibly close the connection.

This can happen if the other side crashes and then comes back up or if it calls close() on the socket while there is data from you in transit, and is an indication to you that some of the data that you previously sent may not have been received.

It is up to you whether that is an error; if the information you were sending was only for the benefit of the remote client then it may not matter that any final data may have been lost. However you should close the socket and free up any other resources associated with the connection.


If you set the socket option SO_LINGER to zero when opening a new socket, then close it normally, the RST bit will be set. So ALL connection will end with a reset. Don't try this it at home, its just annoying. stackoverflow.com/questions/3757289
How to fix this issue then, do we need to restart both remote and our host?
@user2225190 You need to reconnect the client, but first you need to examine your software to make sure it isn't due to an application protocol error, i.e. closing a connection that the other end is still writing to.
Thanks for your comment. It used to work for two months. I am also trying it from a command line, but still getting this error. I tries "sftp user@machine". Error is inconsistent.
It's also very common to be sent by routing hardware which reboots, in which case neither a server or a client sent the resetting message, so it can be a misleading message.