Reprinted: http://blog.csdn.net/chensichensi/article/details/5263132
Time-Wait Status
- Only one Party that initiates an active shutdown enters this status. The exception is that both parties close the service at the same time.
- In this state, the stay time is 2msl, MSL is defined as 30 seconds to 2 minutes, Linux is defined as 30 seconds, so stay for 1 minute
- If data reaches this status, reset the timer.
In the Time-Wait Status, the connection is closed by the other party, and no data will arrive.
The following describes the necessity of Time-wait:
- For the active closing party, an ACK should be sent to the other party to confirm the closing. This ACK packet may be lost, so you can set a wait time. If the other party retransmits the FIN packet, you can also confirm it by sending the ACK packet;
- Due to network latency, some data packets may arrive after they are re-transmitted. In this case, if the connection is closed and both parties establish a connection with the same address, the data packet may be considered as the data packet for this connection. With time-Wait, the old connection exists when the data packet disappears from the network, so it will not interfere with the new connection described above.
Time-Wait accident (forced end of time not reached)
In rfc793, when the connection is in the Time-Wait status, if the RST message is received, TCP should immediately close the connection.
Rfc1337 describes this problem. The solution for Linux is to ignore this rst if rfc1337 is enabled,
Otherwise, the connection is closed.
If (Th-> RST ){
/* This is time_wait assassination, in two flavors.
* Oh well... nobody has a sufficient solution to this
* Protocol bug yet.
*/
If (sysctl_tcp_rfc1337 = 0 ){
Kill:
Inet_twsk_deschedule (TW, & tcp_death_row );
Inet_twsk_put (TW );
Return tcp_tw_success;
}
}
Another scenario occurs manually. For the so_linger socket option, if you enable linger and set
If the linger time is 0, the RST returns the time-Wait Status. Therefore, this option cannot be set.