Menu

Memory leak? (not threads)

Help
Brian
2008-07-09
2012-09-19
  • Brian

    Brian - 2008-07-09

    It looks like there's a memory leak in MySQLdb: Execute the following and watch the memory usage grow:

    import MySQLdb
    while 1:
    try:
    conn = MySQLdb.connect(host="10.1.2.3", user="username", passwd="password", db="database")
    conn.close()
    except:
    pass

    The try/except is there because after several thousand connections I occasionally get "Can't connect to MySQL server" exceptions - even though the server reports at most one connection (using "show full processlist"). I don't know if this is related to the memory leak or simply that MySQL can't cope with that many connects/closes in a short space of time.

    I've found a couple of similar messages:
    http://sourceforge.net/forum/message.php?msg_id=4633174
    http://readlist.com/lists/python.org/python-list/12/62309.html
    However, neither of these have any answers.

    There's also a bug at: http://sourceforge.net/tracker/index.php?func=detail&aid=1836912&group_id=22307&atid=374932
    but that seems to be only related to Threads (which doesn't apply in this case - does it? I confess I didn't fully understand it!)

    I'm using Ubuntu 8.10 with pre-installed Python 2.5.2, MySQLdb 1.2.2final and MySQL 5.0.45

    Am I doing something wrong - or is this in fact related to mysql_thread_end() not being called even though I'm not using threads?

    Help! :)

    Thanks,
    Brian

     
    • Brian

      Brian - 2008-07-15

      I've tried this out on an older version of Ubuntu (7.10) with Python2.5.1 and MySQLdb1.2.2 and the problem doesn't seem to be there (or at least nowhere near as bad). But it's still there on another Ubuntu 8.04 box. I'm guessing this means the problem isn't due to MySQLdb itself but some underlying cause.

      Perhaps someone could try it out on another version of linux? It takes about 5-10 minutes before you can notice the memory usage is growing for the process (using "top" or "free -m") and if I leave it overnight it's using 90% of the memory by the morning.

      Is it possible this is related to the threading bug (even though I'm not using threads?) at http://sourceforge.net/tracker/index.php?func=detail&aid=1836912&group_id=22307&atid=374932

      Thanks!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.