mysqldb issue
Steve Holden
steve at holdenweb.com
Thu Mar 10 12:55:15 EST 2005
fedor wrote:
> Hi all,
>
> I have a problem with mysql connections. After about 28000-29000
> connections, I get a "Can't connect to MySQL server on '127.0.0.1'" error.
>
> I have made a small program which generates the error
>
> """
> import MySQLdb
>
> for i in range(30000):
> if not i % 100:
> print i
> db = MySQLdb.connect(host='127.0.0.1', user='me',passwd='mypassword')
> c = db.cursor()
> c.close()
> db.close()
> """
> This is the error after making about 28200 connections:
> '''
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/tmp/python-12448vuu", line 7, in ?
> db = MySQLdb.connect(host='127.0.0.1', user='me', passwd='mypassword')
> File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", line
> 64, in Connect
> return apply(Connection, args, kwargs)
> File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py",
> line
> 116, in __init__
> self._make_connection(args, kwargs2)
> File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py",
> line
> 41, in _make_connection
> apply(super(ConnectionBase, self).__init__, args, kwargs)
> _mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server
> on
> '127.0.0.1' (99)")
> '''
>
> Does anybody know how to solve this issue?
>
>
I'm not sure this is something you'll see in Real Life (tm). Try running
an overnight test to see whether sleeping for 100 milliseconds between
connections makes the problem go away. If it does, then you are just
running our of available TCP ports.
There's a delay period after a TCP connection is closed and before the
same port number can be re-used by another local process.
If you run your test as it is currently written and after it fails run
netstat -an
you should see a large number of connections in the TIME_WAIT state. If
so then you probably have nothing much to worry about.
regards
Steve
More information about the Python-list
mailing list