[Zz] About time_wait

Source: Internet
Author: User
After the TCP/IP connection established between the client and the server is transferred, the port connected to the server after the socket is closed
The status is time_wait.

Is it true that all sockets that execute active shutdown will enter the time_wait status?
Is there any situation in which the socket that is automatically closed directly enters the closed state?
After the last Ack is sent, the party that closes the task will enter the time_wait status and stay in the 2msl (max segment lifetime) time.
This is essential for TCP/IP, that is, it cannot be solved.

That is, the TCP/IP designer was designed like this.
There are two main reasons:
1. Prevent the package in the last connection from appearing again after getting lost (resending the package), affecting the New Connection
(After 2msl, all repeated packets in the last connection will disappear)
2. Close TCP connection reliably
The last ack (FIN) sent by the active shutdown party may be lost, and the passive party will resend it.
Fin. If the active Party is in the closed state, it will respond to the RST instead of ack. So
The active party must be in the time_wait state, not the closed state.

Time_wait does not occupy a large amount of resources unless it is attacked.

Also, if one side sends or Recv timeout, it will directly enter the closed status.

MSL (maximum segment lifetime) indicates the maximum lifetime of TCP packets over the Internet.
You must select a specific MSL value. RFC 1122 is recommended to be 2 minutes, but the traditional BSD implementation takes 30 seconds.

The maximum retention time of time_wait status is 2 * MSL, that is, 1-4 minutes.

Why do we need time_wait status?

Assuming that the final Ack is lost, the server resends the fin and the client must maintain the TCP status information so that the server can resend the fin.
The final ack. Otherwise, the RST will be sent, and the result server considers the error to occur. TCP must end the connection reliably.
The client must enter the time_wait status because the client may
Returns the final ack.

{
SCZ

The party that calls close () first enters the time_wait status.
}

In addition, considering one situation, TCP may face two equally related quintuple. If the previous connection
The connection is in the time_wait status, and allows another connection with the same related quintuple to appear.
When a TCP packet is sent, the two connections interfere with each other. This situation needs to be considered when the so_reuseaddr option is used.

Why does the time_wait status need to be kept 2msl for so long?

If the time_wait status is not long enough (for example, less than 2msl), the first connection is terminated normally.
The second connection with the same related quintuple appears, and the first connection's repeated packets arrive, interfering with the second
Connections. TCP must prevent repeated packets of a connection from appearing after the connection is terminated.
The status remains long enough (2msl), and the TCP packets in the corresponding direction are either completely responded or
Discard. The second connection is not obfuscated.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.