Skip to content

Connection memory leak without close() #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shirauix opened this issue Jun 15, 2017 · 2 comments · Fixed by #182
Closed

Connection memory leak without close() #181

shirauix opened this issue Jun 15, 2017 · 2 comments · Fixed by #182

Comments

@shirauix
Copy link

Connection object without calling close() explicitly will cause memory leak.

How to reproduce

import MySQLdb

params = dict(
    host = "...",
    db = "...",
    user = "...",
    passwd = "..."
)

while True:
    conn = MySQLdb.connect(**params)
    # forget conn.close() !!!

Cause?

In _mysql.c/_mysql_ConnectionObject_dealloc, _mysql_ConnectionObject_clear() is not called, so it seems that self->converter will not be released.

It seems to be a side effect of commit below:
21a91a2#diff-b86fdc88461d69279e84018bca8ea267

Discussion

I think that calling close() explicitly is the best way, but there is room for consideration:

  • Connection object can be created as context manager (like with MySQLdb.connect() as cursor:), but close() is not called in __exit__()
  • close() is not found in the document
@methane
Copy link
Member

methane commented Jun 15, 2017

In _mysql.c/_mysql_ConnectionObject_dealloc, _mysql_ConnectionObject_clear() is not called, so it seems that self->converter will not be released.

Nice catch.

Connection object can be created as context manager (like with MySQLdb.connect() as cursor:), but close() is not called in exit()

I can't implement it for now, for backward compatibility.

close() is not found in the document

documented here.
I don't have motivation to write poor copy of PEP 249 in mysqlclient-python own document.

@shirauix
Copy link
Author

shirauix commented Jun 16, 2017

Thank you for your quick response.

I can't implement it for now, for backward compatibility.

Understood.

documented here.
I don't have motivation to write poor copy of PEP 249 in mysqlclient-python own document.

I think so too. I will see PEP 249 spec from now on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants