pingcap / pingcap/tidb

Unexpected connection close when executing `kill query` on idle connection

Open
#57,840 0 comments 0 reactions 0 assignees View on GitHub
may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```
session 1:
mysql> show processlist;
+-----------+------+----------------+------+---------+------+------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----------+------+----------------+------+---------+------+------------+------------------+
| 346030088 | root | 10.2.8.3:48768 | NULL | Query | 0 | autocommit | show processlist |
| 346030086 | root | 10.2.8.3:48696 | NULL | Sleep | 7 | autocommit | NULL |
+-----------+------+----------------+------+---------+------+------------+------------------+
2 rows in set (0.00 sec)

mysql> kill tidb query 346030086;
Query OK, 0 rows affected (0.00 sec)

session 2:
mysql> show processlist;
ERROR 2013 (HY000): Lost connection to MySQL server during query
```

### 2. What did you expect to see? (Required)

The connection for session 2 shouldn't be closed.

### 3. What did you see instead (Required)

The connection is closed and the i/o timeout error is reporterd in TiDB log like the following:
```
[2024/11/29 18:22:02.430 +08:00] [INFO] [server.go:897] [kill] [conn=346030086] [query=true] [maxExecutionTime=false] [runawayExceed=false]
[2024/11/29 18:22:02.431 +08:00] [WARN] [sqlkiller.go:61] ["kill initiated"] ["connection ID"=346030086] [reason="[executor:1317]Query execution was interrupted"]
[2024/11/29 18:22:02.431 +08:00] [INFO] [conn.go:1106] ["read packet timeout, close this connection"] [conn=346030086] [session_alias=] [idle=18.588288003s] [waitTimeout=28800] [error="read tcp 10.2.8.3:26333->10.2.8.3:48696: i/o timeout"]
```

### 4. What is your TiDB version? (Required)

v8.3.0

Contributor guide

Open the contributing guide

Research direction

Reproduce the two-session sequence from the issue on TiDB v8.3.0, then trace the logged paths in server.go:897, sqlkiller.go:61, and conn.go:1106. Compare the idle connection's kill handling with the read-packet timeout path; done means killing the idle query no longer closes session 2 or reports the timeout shown in the log.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.