当前位置:网站首页>I'm afraid of the goose factory!
I'm afraid of the goose factory!
2022-06-25 10:08:00 【Southern kingdom_ Love】
A reader came to me last week and said , When he interviewed Tencent , With this problem :
This belongs to TCP Scenario of abnormal disconnection , This part is in my 「 Graphic network 」 It's not detailed yet , Take this opportunity to make up for it .
Kobayashi csdn Wrote a lot of graphic network articles , A total of 15 swastika And draw 500 Pictures , Yes csdn My friend suggested that I organize the illustrated network articles into electronic files , It's easy for readers to read .
That must be , So Kobayashi spent some time sorting out the graphic network electronic documents , The effect is like the title :
You can use it as a handbook for interview Raiders , Now open source for everyone to download : Click download graphic network PDF
Okay , Continue today's theme .
There are several key words to this question :
It's not turned on keepalive;
There has been no data interaction ;
Process breakdown ;
Host crash ;
Let's first know what is TCP keepalive Well ?
This thing is actually TCP The survival mechanism of , How it works, as I've written in previous articles , Just post the previous content here .
If it's on both ends TCP The connection has never had data interaction , Reached the trigger TCP The conditions for the survival mechanism , So what's in the kernel TCP The protocol stack will send a probe message .
If the peer program works properly . When TCP The live detection message is sent to the opposite end , The opposite end will respond normally , such TCP The hold time will be reset , Wait for the next TCP The arrival of survival time .
If the peer host crashes , Or the message is unreachable due to other reasons . When TCP After the live detection message is sent to the opposite end , Under the , No response , Several times in a row , After reaching the number of live detection ,TCP It will be reported that TCP The connection is dead .
therefore ,TCP The livekeeping mechanism can be used when there is no data interaction between the two parties , By detecting messages , To determine the other person's TCP Is the connection alive .
Be careful , If the application wants to use TCP The survival mechanism needs to go through socket Interface setup SO_KEEPALIVE Options will work , If not set , Then you can't use TCP The survival mechanism .
got it TCP keepalive effect , Let's go back to the topic 「 Host crash 」 This situation .
Before opening TCP keepalive, And there has been no data interaction between the two sides , If the client's 「 Host crash 」 了 , What's going to happen .
The client host crashed , The server cannot perceive it , In addition, the server is not turned on TCP keepalive, Without data interaction , Server side TCP The connection will always be in ESTABLISHED Connection status , Until the server restarts the process .
therefore , We can get a point , Before use TCP Keep the mechanism alive and both parties do not transmit data , One side TCP The connection is in ESTABLISHED state , It does not mean that the other party's connection must be normal .
In that title 「 Process breakdown 」 In the case? ?
I did my own experiment , Use kill -9 To simulate a process crash , Found in kill After dropping the process , The server will send FIN message , Four waves with the client .
therefore , Even if it's not turned on TCP keepalive, And there is no data interaction between the two sides , If one of the processes crashes , This process is perceptible to the operating system , So it's going to send FIN Message to the other party , And then with each other TCP Four waves .
The above is the answer to this interview question , Next let's look at 「 There's data transmission 」 Some anomalies in the scene of :
The first one is , Client host down , It's going to restart again , What's going to happen ?
The second kind , Client host down , There has been no restart , What's going to happen ?
Client host down , It's going to restart again
After the client host goes down , The message sent by the server to the client will not get any response , After a certain period of time , The server will trigger the timeout retransmission mechanism , Retransmit the unresponsive message .
In the process of retransmission message by server , After the client host restarts , The client's kernel will receive the retransmitted message , Then it is transmitted to the corresponding process according to the message information :
If there is no process listening on the client host TCP The destination port number of the message , Then the client kernel will ** reply RST message , Reset this TCP Connect *;
If there is a process listening on the client host TCP The destination port number of the message , Due to the client host after restart , Previous TCP The data structure of the connection has been lost , The protocol stack in the client kernel will find that the TCP Connected socket Structure , And I will reply RST message , Reset this TCP Connect .
therefore , As long as one party restarts , Before you receive it TCP Connected message , I'll reply RST message , To disconnect .
Client host down , There has been no restart
This situation , When the number of times of retransmission message reaches a certain threshold , The kernel will determine that TCP There is a problem , And then through Socket The interface tells the application to TCP There's something wrong with the connection , It is commonly ETIMEOUT Status code .
How many retransmissions are there ?
stay Linux In the system , Provide one called tcp_retries2 Configuration item , The default value is 15, Here's the picture :
This kernel parameter is control , stay TCP When the connection is established , The maximum number of timeout retransmissions .
however tcp_retries2 Set up 15 Time , Doesn't mean TCP Retransmission over time 15 Will notify the application to terminate the TCP Connect , The kernel will also be based on 「 Maximum timeout 」 To determine .
The timeout time of each round increases in multiples , For example, the first time a timeout retransmission is triggered is in 2s after , The second time is in 4s after , The third time is 8s after , And so on .
The kernel will be based on tcp_retries2 Set the value of the , Calculate a maximum timeout .
When the message is retransmitted and no response is received , Arrive first 「 Maximum number of retransmissions 」 perhaps 「 Maximum timeout 」 After one of these two conditions , Will stop retransmission .
Finally ,TCP frigging awesome , Every exception is taken into account .
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Kobayashi coding」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/qq_34827674/article/details/117922761
边栏推荐
- Vscode attempted to write the procedure to a pipeline that does not exist
- Mengyou Technology: six elements of tiktok's home page decoration, how to break ten thousand dollars in three days
- Etcd tutorial - Chapter 4 etcd cluster security configuration
- x86电脑上下载debian的arm64的包
- How do wechat sell small commodity programs do? How to open wechat apps to sell things?
- Learning notes of rxjs takeuntil operator
- ShardingSphere-Proxy 5.0 分库分表(一)
- Mengyou Technology: tiktok live broadcast with goods elements hot topics retention skills shaping image highlight selling points
- The way that flutter makes the keyboard disappear (forwarding from the dependent window)
- Flask博客实战 - 实现侧边栏最新文章及搜索
猜你喜欢

puzzle(019.2)六边锁

Exception: gradle task assemblydebug failed with exit code 1

Chitubox micromake l3+ slicing software configuration correspondence
![[MySQL learning notes 21] storage engine](/img/3a/a3cd573281efc689cafdb7d7562ce0.png)
[MySQL learning notes 21] storage engine

Webapi performance optimization

Vscode attempted to write the procedure to a pipeline that does not exist

Remove the mosaic, there's a way, attached with the running tutorial

Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?

Jetpack compose layout (I) - basic knowledge of layout

Download the arm64 package of Debian on X86 computer
随机推荐
Flutter Gaode map privacy compliance error
WebApi性能优化
Tiktok brand goes to sea: both exposure and transformation are required. What are the skills of information flow advertising?
Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!
Etcd教程 — 第四章 Etcd集群安全配置
Chitubox micromake l3+ slicing software configuration correspondence
Neat Syntax Design of an ETL Language (Part 2)
Encoding format for x86
Modbus协议与SerialPort端口读写
Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
8. Intelligent transportation project (1)
View. post VS Handler. Differences and usage scenarios of post
Shardingsphere proxy 4.1 sub database and sub table
依赖属性、依赖附加属性以及类型转换
Arduino bootloader burning summary
(forwarding articles) after skipping multiple pages, shuttle returns to the first page and passes parameters
How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
PHP obtains the IP address, and the apache2 server runs without error
Wechat official account can reply messages normally, but it still prompts that the service provided by the official account has failed. Please try again later
The problem of automatic page refresh after the flyer WebView pops up the soft keyboard