The value of tidb_server_connections is less than 0

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb_server_connections存在小于0的值

| username: dba-kit

After upgrading to 7.5.2, I found that in some scenarios, the total number of connections for tidb-server in the monitoring is actually a negative number.

| username: WinterLiu | Original post link

Strange, could it be a bug or a misunderstanding?

| username: 有猫万事足 | Original post link

Before version 7.5.2, there was indeed this bug. But judging by the fix time, it should be resolved in 7.5.2.
Maybe these erroneous data were from before the upgrade?
Not sure if that’s the case. If it’s still wrong, please provide feedback in the issue to check.

| username: dba-kit | Original post link

Uh, I also reported this BUG. Previously, it was even more exaggerated, almost all zeros. Also, looking at it today, the value has become -65, and it will probably keep accumulating…

| username: TIDB-Learner | Original post link

:joy: :joy: The connection is 0 and cannot be negative.

| username: Billmay表妹 | Original post link

You forgot to categorize it under product defects!

| username: dba-kit | Original post link

Uh, indeed, it was only put in the suggestions and feedback section…

| username: 希希希望啊 | Original post link

It’s a bug that has always existed, but it’s not a big deal.

| username: jhm633 | Original post link

This is a known issue, and you can track the progress with this issue: The Connection Count panel in the Grafana dashboard is inaccurate. · Issue #54428 · pingcap/tidb · GitHub. This problem is relatively difficult to pinpoint as it involves a lot of code. If you have any scenarios or clues that trigger the issue, please provide them. Thank you.

| username: dba-kit | Original post link

Now it’s even more exaggerated. The total number of connections for the tidb-server node ending in 245, which is set to default, has actually reached -1724.

| username: YangKeao | Original post link

If the connection exits before it is fully established, it may cause the Connection Count to decrease by one, making it smaller than the actual value. An easy way to reproduce this is: use the MySQL CLI to connect to a non-existent user (or connect with an incorrect password), and TiDB’s Connection Count will decrease by one, making it smaller than the actual value.

There is a PR fixing this issue! server: refine the connection counter logic by YangKeao · Pull Request #54546 · pingcap/tidb · GitHub

| username: MrSylar | Original post link

Learned.

| username: TiDBer_7S8XqKfl | Original post link

Looking forward to the official solution.