Bug #93394 memory leak when csv engine has no permission to meta file
Submitted: 29 Nov 2018 5:46 Modified: 29 Nov 2018 6:26
Reporter: Yan Huang (OCA) Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: CSV Severity:S3 (Non-critical)
Version:5.7.21 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[29 Nov 2018 5:46] Yan Huang
memory leak when csv engine has no permission to meta file

How to repeat:
Take table `general_log` as an example:

1. make mysql no write permission to meta file: `chown root: data/general_log.*` and `chmod 744 data/general_log.*`
2. query "select * from mysql.general_log" after restarting mysql
3. the query hang, and mysqld keep consuming memory

Suggested fix:
I think the causes of the memory leak are:

1. `ha_tina::open` open meta file (.CSM file) with `O_RDWR|O_CREAT`, which will fail with permission denied in this case
2. `ha_tina::repair` check only data file (.CSV file)
3. When `ha_tina::open` failed, mysqld will repair engine. And `ha_tina::repair` succeed, then mysqld reopen table with `ha_tina::open`, which will loop forever.
4. In the loop, memory is allocated from `THD::mem_root`, which will be free when sql finish.

A patch is attached to fix the loop.
[29 Nov 2018 5:48] Yan Huang

Attachment: 93394.diff (application/octet-stream, text), 3.67 KiB.

[29 Nov 2018 5:49] Yan Huang

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: 93394.diff (application/octet-stream, text), 3.67 KiB.

[29 Nov 2018 6:26] Umesh Shastry
Hello Yan Huang,

Thank you for the report and contribution!