2006 - Mysql has gone away

Asked by Babu Reddy

I am using Python 2.4.3, mod_python with apache 2.2, PySQLPool 0.3, Mysql 5.0.45 and MySQLdb 1.2.2 and I keep getting "2006, 'MySQL server has gone away' "

Reloading apache works for a while, but thows this error after sometime.

How do I check if a connection is valid? The connection_timeout parameter on mysql is set to a large value 100000 secs, which is more than 24 hours.

Question information

English Edit question
PySQLPool Edit question
No assignee Edit question
Solved by:
Nikoleta Verbeck
Last query:
Last reply:
Revision history for this message
Nikoleta Verbeck (nerdynick) said :

Try getting the latest SVN Checkout. I do plan to put up a tar.gz tonight if not tomorrow of the 0.3.1 release that should fix a lot of the small bugs and increase performance.

PySQLPool should be doing the connection testing on its own and with the 0.3.1 release it contains a MySQL Connection timeout variable that tells it how often it should validate that the connection is active. By default I believe this is 10 or 15secs.

Also to note that when using PySQLPool or any other DB class in a web framework you should create a Tool and/or Plugin for the framework that closes the connections at the end of every request. I do have a small tool and a plugin for CherryPy that takes care of this. The problems that I have come across is that the DB Classes are expecting the connection to remain open but when MySQL times these connections out the DB Class has to wait tell the next call to the DB before it can validate that the connection is still open. This ends up leading to a bunch of locked sockets on the web servers and can only be cleared by reloading apache. Had this problem happen to me in a CherryPy/mod_wsgi cluster that I released into a very active cluster.

Revision history for this message
Best Nikoleta Verbeck (nerdynick) said :

Just uploaded V0.3.1 if you would wish to give it a try. You can download it here: http://pysqlpool.googlecode.com/files/PySQLPool_V0.3.1.tar.gz

Revision history for this message
Babu Reddy (babureddy) said :

Thanks Nick Verbeck, that solved my question.