Tracker: Bugs

5 memory leak related to charset='utf8' - ID: 2125250
Last Update: Comment added ( sf-robot )

I'm using MySQLdb 1.2.2, but I can repro the memory leak with today's trunk. Hence, I'm pretty sure this isn't repro-specific.

mysql Ver 14.12 Distrib 5.0.51, for apple-darwin9.2.1 (i686) using EditLine wrapper

Python 2.5.2

I'm using MacPorts on OS X 10.5, but I can repro this on Linux.

Darwin Macintosh-4.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun 9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386

#####################################################

# This program leaks memory rather quickly. Removing the charset
# parameter fixes it.

import MySQLdb
import sys


while True:
connection = MySQLdb.connect(
user='user', passwd='password',
host='localhost', db='development',
charset='utf8')
try:
cursor = connection.cursor()
cursor.execute(
'select * from atoms where false')
sys.stdout.write('.')
sys.stdout.flush()
finally:
connection.close()


Shannon -jj Behrens ( jjinux ) - 2008-09-23 14:33:47 PDT

5

Closed

Fixed

Kyle VanderBeek

MySQLdb

MySQLdb-1.2

Public


Comments ( 18 )

Date: 2009-03-18 11:57:08 PDT
Sender: sf-robotSourceForge.net Site Admin

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).


Date: 2009-02-27 16:34:44 PST
Sender: kylevAccepting Donations

Hrm, thought I marked this pending for 1.2.3b2...


Date: 2009-02-25 01:03:38 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

I tried it out on 1.2br. It builds under MacPorts, which is awesome.
Better yet, it no longer leaks! Two thumbs way up :-D


Date: 2009-02-23 19:15:13 PST
Sender: kylevAccepting Donations

Ok, the patch is applied to both 1.2br and trunk. Will mark closed once
1.2.3b2 is released.


Date: 2009-02-23 15:15:38 PST
Sender: kylevAccepting Donations

JJ - the attached patch should fix the "holy crap it leaks like a sieve"
situation. Please test it, and I'll get Andy to put this in 1.2.3b2.


Date: 2009-02-18 11:08:37 PST
Sender: kylevAccepting Donations

I now have a working repro! I have some leads on the leak, but nothing
definite yet. Thanks jj.


Date: 2009-02-17 16:07:32 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

Sure:

CREATE DATABASE development
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

...

CREATE TABLE atoms (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,

active TINYINT NOT NULL DEFAULT 1,

url TEXT NOT NULL,
name VARCHAR(255),
blurb VARCHAR(255),
thumbnail TEXT,

UNIQUE INDEX (url(255)),
INDEX (name)
) ENGINE = INNODB;


Date: 2009-02-17 11:09:14 PST
Sender: kylevAccepting Donations

jj, can you give me the complete CREATE TABLE for the "atoms" table
referenced by your script? I have a dummy table in my test db and it
doesn't leak. I'm mostly interested in the CHARSET and ENGINE you're
using.

I've made SVN trunk kind-of work again... Some partially finished work on
conversions and encoding is present, so trunk isn't that stable right now.


Date: 2009-02-16 22:43:50 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

I tried out MySQL-python-1.2.3b1 on Ubuntu 8.04 with Python 2.5. It still
leaks.


Date: 2009-02-16 20:14:15 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

Ugh, trying to build MySQLdb on MacPorts is *hard*. I'm going to have a
hard time testing 1.2br.


Date: 2009-02-16 19:32:32 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

> jj, are you still seeing this? I can't repro it. I've tried on trunk
and
1.2br, and my python process stays the exact same size (on Fedora 10).

Hey, Kyle!

Does trunk actually take care of encodings? The last time I tried it, it
didn't
https://sourceforge.net/tracker/index.php?func=detail&aid=2127852&group_id=22307&atid=374932.
Of course, that was a long time ago.

I haven't tried 1.2br. I'll try that next.

Thanks for the update :)


Date: 2009-02-16 19:30:08 PST
Sender: jjinuxSourceForge.net DonorAccepting Donations

> charset='utf8', use_unicode=False

Markus, thanks for the tip. You're right that setting use_unicode=False
fixes the memory leak. However, if I set that then MySQLdb gives me UTF-8
strings instead of unicode objects. I'm not using SQLAlchemy, so I'd
really much prefer MySQLdb to give me unicode objects.

(Note, I use SQLAlchemy when I have a little bit of very complex data, and
I use naked SQL when I have a lot of very simple data. In my current
project, I have only three tables, but I have 10s of gigs of data.)


Date: 2009-02-04 16:47:32 PST
Sender: kylevAccepting Donations

jj, are you still seeing this? I can't repro it. I've tried on trunk and
1.2br, and my python process stays the exact same size (on Fedora 10).


Date: 2009-01-09 01:52:32 PST
Sender: markus_gritsch

> # This program leaks memory rather quickly. Removing the charset
> # parameter fixes it.

Using the parameters

charset='utf8', use_unicode=False

also shows no leaking and should therefore be used as a temporary
workaround for 1.2.2 as mentioned at
http://www.sqlalchemy.org/trac/wiki/DatabaseNotes#MySQL


Date: 2009-01-08 17:55:18 PST
Sender: eikenberry

Any idea what the change was in trunk that fixed this?


Date: 2008-09-26 16:40:04 PDT
Sender: jjinuxSourceForge.net DonorAccepting Donations

Sorry, I'm going to reopen this; I was the one who originally closed it.
It turns out that MySQLdb 1.3 on trunk doesn't actually respect
charset='utf8'. See
http://sourceforge.net/tracker/index.php?func=detail&aid=2127852&group_id=22307&atid=374932.
Hence, it's very well possible that MySQLdb might leak memory again after
that bug is fixed.


Date: 2008-09-23 15:13:45 PDT
Sender: jjinuxSourceForge.net DonorAccepting Donations

Duh, it looks like this has already been fixed in trunk. I was running it
wrong earlier. It definitely leaks in 1.2.2, but it does not appear to
leak in trunk. Closing and marking as invalid.


Date: 2008-09-23 14:35:40 PDT
Sender: jjinuxSourceForge.net DonorAccepting Donations

File Added: mysqlleak.py


Attached Files ( 2 )

Filename Description Download
mysqlleak.py This is a short script that causes a memory leak. Just run it and monitor top. Download
MySQLdb-1_2-unicode-leak.diff Fix several potential leaks during converter iteration. Download

Changes ( 19 )

Field Old Value Date By
status_id Pending 2009-03-18 11:57:08 PDT sf-robot
allow_comments 1 2009-03-18 11:57:08 PDT sf-robot
close_date 2009-02-27 16:34 2009-03-18 11:57:08 PDT sf-robot
close_date - 2009-02-27 16:34:45 PST kylev
status_id Open 2009-02-27 16:34:45 PST kylev
close_date 2009-02-23 19:15 2009-02-25 01:03:38 PST jjinux
status_id Pending 2009-02-25 01:03:38 PST jjinux
assigned_to adustman 2009-02-23 19:15:13 PST kylev
status_id Open 2009-02-23 19:15:13 PST kylev
resolution_id None 2009-02-23 19:15:13 PST kylev
close_date - 2009-02-23 19:15:13 PST kylev
File Added 314869: MySQLdb-1_2-unicode-leak.diff 2009-02-23 15:14:24 PST kylev
close_date 2008-09-23 15:13 2008-09-26 16:40:04 PDT jjinux
resolution_id Invalid 2008-09-26 16:40:04 PDT jjinux
status_id Closed 2008-09-26 16:40:04 PDT jjinux
close_date - 2008-09-23 15:13:45 PDT jjinux
resolution_id None 2008-09-23 15:13:45 PDT jjinux
status_id Open 2008-09-23 15:13:45 PDT jjinux
File Added 294616: mysqlleak.py 2008-09-23 14:35:40 PDT jjinux