Bug #110941 mysql server not cleaning up certain queries on TCP disconnections

Submitted: 5 May 2023 22:22 Modified: 8 May 2023 8:47
Reporter: Jay Janssen Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Connection Handling Severity:S3 (Non-critical)
Version:8.0.32, 8.0.33 OS:Any
Assigned to: CPU Architecture:Any

[5 May 2023 22:22] Jay Janssen
Description:
I've noticed that mysql is not cleaning up certain running queries when a client disconnects while the query is running.    This is most noticeable if I have a `TRUNCATE TABLE` that is blocked on a backup lock (i.e.,: https://bugs.mysql.com/bug.php?id=110820).

See test case below.  My test case is contrived, but it illustrates a broader point:  MySQL doesn't seem to do a great job of cleaning up from clients who are obviously gone.    The same thing is not true if I use something like `SELECT SLEEP(1000)` instead of the truncate command.   Possibly this is an issue with all queries in a lock wait state.  

In my other bug, I have a monitoring tool using TRUNCATE on P_S tables very frequently.  Because the truncate blocks indefinitely, I get a LOT of threads trying to truncate, even if my monitoring tool disconnects.  

How to repeat:
Have two terminals open:

mysql2> lock instance for backup;
Query OK, 0 rows affected (0.00 sec)

mysql1> truncate performance_schema.table_io_waits_summary_by_table; # Blocks

mysql2> show processlist;
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
| Id  | User            | Host            | db                 | Command | Time  | State                   | Info                                     |
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
|   5 | event_scheduler | localhost       | NULL               | Daemon  | 21927 | Waiting on empty queue  | NULL                                     |
|  10 | root            | localhost       | NULL               | Query   |     0 | init                    | show processlist                         |
| 742 | test            | 127.0.0.1:43468 | performance_schema | Query   |     6 | Waiting for backup lock | truncate table_io_waits_summary_by_table |
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
3 rows in set (0.00 sec)

mysql1> # still blocking
^Z
[1]   Terminated              mysql -h 127.0.0.1 -P 3306 -u test --prompt="mysql1> "

[2]+  Stopped                 mysql -h 127.0.0.1 -P 3306 -u test --prompt="mysql1> "
bash-4.4# kill %

[2]+  Stopped                 mysql -h 127.0.0.1 -P 3306 -u test --prompt="mysql1> "

# mysql 1 client has totally disconnected

mysql2> show processlist;
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
| Id  | User            | Host            | db                 | Command | Time  | State                   | Info                                     |
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
|   5 | event_scheduler | localhost       | NULL               | Daemon  | 22091 | Waiting on empty queue  | NULL                                     |
|  10 | root            | localhost       | NULL               | Query   |     0 | init                    | show processlist                         |
| 742 | test            | 127.0.0.1:43468 | performance_schema | Query   |   170 | Waiting for backup lock | truncate table_io_waits_summary_by_table |
+-----+-----------------+-----------------+--------------------+---------+-------+-------------------------+------------------------------------------+
3 rows in set (0.00 sec)

# Query lingers indefinitely

Suggested fix:
I'd expect a client that has totally disconnected via TCP to have it's thread killed.
[8 May 2023 8:47] MySQL Verification Team
Hello Jay Janssen,

Thank you for the report and feedback.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.054 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.