Bug #105858 Memory leak for the innodb_session while killing connection
Submitted: 10 Dec 2021 8:40 Modified: 10 Dec 2021 13:44
Reporter: bai Kevin Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[10 Dec 2021 8:40] bai Kevin
Description:
There is a race condition on the innodb_session between ha_kill_connection and ha_close_connection.
The ha_kill_connection is called by THD:awake() and it holds the LOCK_thd_data, but the ha_close_connection is called by THD::release_resources() and there is no lock holding.

Both the function call the thd_to_innodb_session() to get the innodb_session. If the ha_close_connection deletes the innodb_session and at the same time, ha_kill_connection is calling thd_to_innodb_session() to get the innodb_session, it will generate a new innodb_session object. At last, this new one is not be released and leaks memory.

How to repeat:
It's very hard to repeat it.

Suggested fix:
+  mysql_mutex_lock(&LOCK_thd_data);
   ha_close_connection(this);
+  mysql_mutex_unlock(&LOCK_thd_data);
[10 Dec 2021 13:44] MySQL Verification Team
Hi Mr. Kevin,

Thank you very much for your bug report.

However, we can not process further your report without a repeatable test case. That is the only manner in which we can proceed with further processing of the bug reports.

Another way of processing would be to come with a very thorough, complete code analysis, which would prove unequivocally that what you report is indeed a bug.

Can't repeat.