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?

Recommend

Cloudxtiny: £1.5/month KVM-512MB/5G SSD/100GB/UK data center

Cloudxtiny is a hosting company from the UK, prov...

What are the challenges of using multiple team collaboration apps?

Many companies are already using various team col...

SDN changes the development path of router technology

Over the past 30 years, IP networks with routers ...

The 400G era is coming, and new optical fibers may be the best partner

With the continuous emergence of high-definition ...

Let’s talk about 5G this year

Time is like quicksand, and the 2010s are about t...

Let's talk about the basic principles of common serial communication

Why do we need to talk about serial communication...

TCP and UDP, 123 things you need to know (TCP)

Preface As a network operation and maintenance pe...

What is 5G voice like now?

In the 5G era, real-time communication is still a...

5G development enters its fourth year, and innovation is the key to development

On June 6, 2019, the Ministry of Industry and Inf...

How can the chip industry survive in the era of the Internet of Things?

After the industrial revolution, the computer age...