当前位置:网站首页>MySQL invalid conn troubleshooting
MySQL invalid conn troubleshooting
2022-07-23 11:52:00 【Blue fat man's programming dream】

Service usage golang , The client library is go-mysql-driver , The system test environment is frequent but not always reported invalid conn error , But actually take sql The execution is normal .

Cause analysis

Because the connection is invalid , First, consider that the client uses expired connections .
mysql Both the server and the client can configure the maximum life cycle of their connections .
If the maximum life cycle of the connection configured by the client is greater than that of the server , And the client has no mechanism for reconnecting invalid connections , It will cause the connection of the server to expire , The client uses an expired connection , triggering invalid conn.
Inquire about mysql Maximum idle life cycle of the connection s In units of .


Client maximum lifecycle configuration

mysql server The maximum life cycle of is greater than golang The maximum connection life cycle of the client , So eliminate this reason .

There was a stalemate for a moment , Why on earth is the connection invalid . Direct packet capture analysis .

The expert system finds abnormal packages
take pcap For documents wireshark open , Use expert system to analyze the caught package as a whole .
See there are 8 An unusual RST package , The normal connection switch will not have RST Produced , Focus on the analysis RST Cause of occurrence .

Find the problem

See the specific abnormal place ,mysql The server is replying to a client ACK After the news , The client waited 10s Yes mysql The server initiated Request Quit(mysql agreement ) Command to close the connection .
See the details before and after the abnormality .
Choose... From the menu bar Statistics->Flow Graph, You can open the data flow diagram window .

You can see the process as follows :
1,11:55:49.05 On the client side to mysql launch Request Execute Statement perform sql The order of ,
2,mysql recovery Ack
3, however mysql The execution result is not returned to the client , So the client waited 10s Then send the command to close the connection .
4,mysql stay 11:55:59.27 Only then returned the execution result .
5, But at this time, the client has closed the connection , Sending data to a closed connection triggers RST The signal , So the client responds to the server RST
See here , The task that can be clearly performed by the server sql It's overtime , Or the server timed out when it returned the results .

In the further , Is it the alarm caused by timeout ?
You can see that when reading buffer data , It is possible to report ErrInvalidConn

Keep looking at mc.buf.readNext, Timeout code found


Because it's a database , First I thought of disk , Back again top,iostat ,iotop analysis .
This discovery is abnormal .

Disk found io The usage rate will soar occasionally , therefore mysql The execution rate is affected .

The main items that occupy disk utilization are video transcoding , The transcoding time is not fixed , So when transcoding , On the same host mysql Be affected by , Caused a timeout , Cause the application layer to report invalid conn error .
Confirmed , The transcoding function can be temporarily turned off in the test environment , After closing , No more alarms appear .
Under normal circumstances , When you see mysql Return timeout yes , You should check the system immediately io Wait for the hardware index , Because this is the test environment , So I went to see it go-mysql-client Library code , Further confirmation .

The monitoring system of testing environment is not perfect , There is no monitoring interface , Otherwise, you should be able to see the disk at a glance io abnormal .
Secondly, it is late to return to the application layer to see the code , Or was invalid conn Confused , In fact, if go-mysql The error reported by the library as a timeout error may be more in line with this scenario .
Actually, from the beginning , Just used it. top and iostat Analyze the system disk occupancy , However, the indicators were not abnormal during that period , Add the reported error information is invalid conn This led me to first locate the problem as a problem with the network connection , And capture and analyze .
See this accidental mistake , Systematic indicators should be continuously observed , This time I just watched it for more than ten seconds and then turned to analyze other factors , It really shouldn't be .
The test environment starts the slow log
set global slow_query_log=1
Check the on Status


边栏推荐
- NFT digital collection system development: Shenzhen Evening News "good times travel" digital collection online seconds chime
- [monitoring deployment practice] display the charts of Prometheus and loki+promtail based on granfana
- DBA命令
- Typescript common types
- NFT digital collection system development, development trend of Digital Collections
- Chinese interpretation of notepad++ background color adjustment options
- 数仓4.0笔记——数仓建模
- sql-labs 5-6通关笔记
- NFT digital collection development /dapp development
- Data warehouse 4.0 notes - user behavior data collection IV
猜你喜欢

數倉4.0筆記——業務數據采集

Compilation principle - detailed explanation of syntax analysis

Adding environment variables and templates to systemctl service

Sqli lab pass 17-22 notes
![[pyrodiomics] the extracted image omics characteristic value is abnormal (many 0 and 1)](/img/73/628e0188e1e2c13e0963746759f691.png)
[pyrodiomics] the extracted image omics characteristic value is abnormal (many 0 and 1)

activiti7快速入门经验分享

Man in the middle attacks ARP Spoofing and its linkage with beef XSS

Security problems of FileInfo in PHP file upload

Websocket long connection

NFT trading platform digital collection system | development and customization
随机推荐
修改mysql的root密码
MySQL视图
MySQL事务
Development of digital collection system: Baidu AI pays tribute to Air China
Data warehouse 4.0 notes - business data collection
shell取某一时间范围内月份
数仓4.0笔记——用户行为数据采集三
Unable to negotiate with port 51732: no matching host key type found. Their offer:
kubesphere haproxy+keepalived (一)
Fed Brad: last week's employment report showed that the U.S. economy is robust and can withstand higher interest rates
软件测试1
Chinese interpretation of notepad++ background color adjustment options
[untitled]
DVWA learning notes
MySQL password free login settings
数仓4.0笔记——用户行为数据采集二
Digital collection development / meta universe digital collection development
[doris] configure and basically use the contents system (continue to add content when you have time)
xtu-ctf Challenges-Reverse 1、2
数字藏品开发/元宇宙数字藏品开发