If the server does not receive the fourth wave request during the four TCP wave requests, will the server keep waiting?

If the server does not receive the fourth wave request during the four TCP wave requests, will the server keep waiting?

I'm going to copy an answer from a certain website and write an article about it.

TCP four times wave

Under normal circumstances, as long as the data transmission is completed, both the client and the server can actively initiate four waves to release the connection.

Just like the picture above, assuming that the four waves are initiated by the client, it is the active party. The server passively receives the client's wave request and is called the passive party.

Both the client and the server are initially in the ESTABLISHED state.

  • First wave: Generally, when the active party executes the close()​ or shutdown()​ method, it will send a FIN message, indicating "I will no longer send data".
  • Second wave: After receiving the FIN message from the active party, the passive party immediately responds with an ACK, which means "I received your FIN and I know you will not send any more data."

The above mentioned is that the active party no longer sends data. But if the passive party still has data to send at this time, then continue to send it. Note that although the passive party can send data to the active party between the second and third wave, it is not certain whether the active party can receive it normally. This will be discussed later.

  • The third wave: After the passive party senses the second wave, it will do a series of finishing work and finally call a close()​, at which time it will send a FIN-ACK for the third wave.
  • The fourth wave: The active party sends an ACK, which means it has been received.

The first and third waves are actively triggered by us in the application (such as calling the close() method), which is what we need to pay attention to when writing code.

The second and fourth waves are automatically completed by the kernel protocol stack. We don't touch this part when writing code, so we don't need to worry too much.

In addition, whether active or passive, each party sends a FIN​ and an ACK​. It also receives a FIN​ and an ACK.

Back to the main question.

If the server does not receive the fourth wave request during the four TCP wave requests, will the server keep waiting?

The fourth wave is triggered by the third wave. If the server does not receive the fourth wave, it will think that its third wave is lost, so the server keeps retrying to send the third wave (FIN). The number of retries is controlled by the system's tcp_orphan_retries parameter. If the server fails to retry many times, it will directly disconnect the connection. So the conclusion is that the server will not keep waiting for the fourth wave.

TCP fourth wave lost

 # cat / proc / sys / net / ipv4 / tcp_orphan_retries
0

In addition, you will find that the tcp_orphan_retries parameter is 0, but it does not mean no retries. When it is 0, the default value is 8, which means 8 retries.

 /* Calculate maximal number or retries on an orphaned socket. */
static int tcp_orphan_retries ( struct sock * sk , int alive )
{
int retries = sysctl_tcp_orphan_retries ; /* May be zero. */

/* We know from an ICMP that something is wrong. */
if ( sk - > sk_err_soft && ! alive )
retries = 0 ;

/* However, if socket sent something recently, select some safe
* number of retries. 8 corresponds to >100 seconds with minimal
* RTO of 200msec. */
if ( retries == 0 && alive )
retries = 8 ;
return retries ;
}

Of course, if the server retries to send the FIN for the third time, using the same port and IP, and a new client is started, the client will regard the retried FIN as an abnormal data packet after it is received, and will directly send a RST to the server, and the connection between the two ends will be disconnected.

<<:  One of the biggest features of 5G is the security minefield

>>:  Why do base stations need to go to the sky?

Blog    

Recommend

Interesting, 5G base station and fire hydrant logo combined

Following the integration of 5G base stations wit...

How can 5G development be realized?

[[375985]] [51CTO.com original article] "If ...

2021 is the year of the explosion of the cellular IoT module industry

According to a new research report from IoT analy...

In the 5G era, what sparks will cloud computing and 5G create?

With the eager anticipation of the whole nation, ...

Energy consumption transformation issues of traditional IDC in the 5G era

[[387217]] In the modern society where technology...

The challenges of 5G have just begun

The COVID-19 outbreak that has ravaged the world ...

Four indicators to help you choose the best multi-service data center provider

A new report from MarketsandMarkets predicts that...