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

PoE, PoE+, PoE++ switches: How to choose?

PoE (or Power over Ethernet) is a proven time-sav...

Why is China's 5G commercialization going astray?

"The 5G race is a race that the United State...

How to Cut an Oxen - Illustrated MySQL 8.0 Optimizer Query Parsing

[[423739]] 1. Background and Architecture We all ...

...

Single Sign On (Single Sign On) is enough to read this article

[[347603]] background In the early stages of ente...

The three major operators announced their operating data for May

Recently, the three major operators released thei...

What are the main application scenarios of 5G?

5G networks offer greater bandwidth than previous...

Cutting in while driving is annoying. WiFi actually takes up lanes too.

Friends who often drive often encounter the pheno...

It took two years for 5G messaging to be officially commercialized. Is that it?

With the development of science and technology, t...

5G private network development will accelerate in 2024

The growing demand for fifth-generation network s...