If I have a process with a connected socket, and I terminate this process, then Windows will cause an RST packet to be sent.
Is it guaranteed (is it documented somewhere) that an RST packet will always be sent when a process terminates, or could a FIN packet be sent instead?
TCP is not supposed to send an RST packet when a connection is closed. To close a connection, TCP goes through the following states on the client side:
FIN_WAIT_1
.FIN_WAIT_1
, TCP waits for an acknowledgement (ACK) from the server.FIN_WAIT_2
.FIN_WAIT_2
, TCP waits for aFIN
packet from the serverFIN
arrives, the client sends anACK
and entersTIME_WAIT
TIME_WAIT
is exited after a while (typically, 30 secs. or 1 minute). The purpose of this state is to make it possible to resend the finalACK
to the server in case it was lost.There is no RST packet anywhere. RST is used to respond to unexpected traffic, not to close a connection.
For example, if you send a TCP packet to port 80, and the server is not running an HTTP server (and assuming the packet makes all the way to the server and is not blocked / ignored), then an RST reply is sent back to the client.