Bug #93711 connection_cext has a memory leak in the python mysql-connector
Submitted: 21 Dec 2018 5:34
Reporter: Alexander Stachniak Email Updates:
Status: Open Impact on me:
Category:Connector / Python Severity:S1 (Critical)
Version:8.0.11 OS:Any
Assigned to: CPU Architecture:Any
Tags: memory leak

[21 Dec 2018 5:34] Alexander Stachniak
The "prepare_for_mysql" function in connection_cext.py builds a strong-reffed list or dict. These references are never deleted, creating a memory leak that persists even after closing and deleting the connection. In situations where large amounts of data need to be inserted in an iterative process, the memory leak can quickly fill the entire available RAM leading to system crash.

How to repeat:
Easy to repeat: create random data, loop through insert statements, and profile the memory allocation assigned to the connector class. Example: https://github.com/zstachniak/Memory-Leak-in-MySQL-Connector/blob/master/memory_leak.ipynb

Suggested fix:
Refactor prepare_for_mysql to use weak references, or perform cleanup after executing.
[6 Feb 7:40] Florian Becker
I stumbled across this bug yesterday and I can confirm the memory leak.