4.12 In a TCP connection, what is the difference between a power outage at one end and a process crash?

Table of contents

TCP keepalive TCP keep-alive mechanism

Host crashes

process crash

Scenarios with data transfer

The client host goes down and restarts quickly

The client host is down and has not been restarted

Summary of TCP connection server downtime and process exit


TCP keepalive  TCP keep-alive mechanism

The TCP keep-alive mechanism needs to be set through the socket interface  SO_KEEPALIVE to take effect

        Define a time period. If there is no connection-related activity within this time period (keep alive time 7200s, two hours), start the TCP keep alive mechanism and start sending a probe message every other time period (75 seconds). If If no response is received for several (9) consecutive detection packets, it is considered that the TCP connection has died.

Host crashes

If the TCP keepalive is not enabled, the client is down, and the server cannot perceive the status of the client. The TCP connection of the server will always be in the ESTABLISHED connection state until the client is restarted.

When the TCP keep-alive mechanism is not used and the two parties do not transmit data, the TCP connection of one party is in the ESTABLISHED state, which does not mean that the connection of the other party is still normal.

process crash

The TCP connection information is maintained by the kernel. When a server process crashes, the kernel needs to reclaim all the TCP connection resources of the process. The kernel sends the first waving FIN message, and the subsequent waving process is also completed in the kernel without the need for a process. participate.

Therefore, after the server process exits, it can still successfully complete the TCP four-way wave process with the client.

Scenarios with data transfer

The client host goes down and restarts quickly

As long as one party restarts and receives the previous TCP connection message, it will reply the RST message to disconnect the connection

The client host is down and has not been restarted

When the number of times the server retransmits packets overtime reaches a certain threshold, the kernel will determine that there is a problem with the TCP, and then tell the application program that there is a problem with the TCP connection through the Socket interface, so the TCP connection on the server will be disconnected.

Summary of TCP connection server downtime and process exit

After unplugging the network cable, does the original TCP connection still exist?

The action of unplugging the network cable will not affect the status of the TCP connection. It depends on what actions both parties have done after unplugging the network cable:

After unplugging the network cable, there is data transmission

The data message sent by the server to the client will not get any response, and the server will trigger the timeout retransmission mechanism to retransmit the data message that has not received a response.

If the network cable is plugged back in during the timeout retransmission process of the server, the client will return an ACK response message.

If it is not plugged back in, it will be disconnected after retransmitting a certain number of times by default 15 times.

No data transmission after unplugging the network cable

If the TCP keepalive mechanism is not enabled  , the TCP connection between the client and the server will always exist after the client unplugs the network cable and both parties do not transmit data.

And if the TCP keepalive mechanism is turned on , after the client unplugs the network cable, even if neither party performs data transmission, after a period of time, TCP will send a detection message:

        If the peer is working normally. The TCP keep-alive detection message is sent to the peer, so that the TCP keep-alive time will be reset and wait for the arrival of the next TCP keep-alive time.

        If the peer host is down and the detection message is unreachable, TCP will report the TCP death

Pull out the network cable summary:

 

Guess you like

Origin blog.csdn.net/super8ayan/article/details/132504287