﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21597	(2006, 'MySQL server has gone away') in django1.6 when wait_timeout passed	ekeydar@…	Aymeric Augustin	"'''EDIT -- THE SOLUTION TO THIS PROBLEM IS EXPLAINED IN [https://code.djangoproject.com/ticket/21597#comment:29 COMMENT 29]. JUST DO WHAT IT SAYS. THANK YOU!'''

----

In django 1.6, when the wait_timeout passed (of mysql), then DB access cause the (2006, 'MySQL server has gone away') error.
This was not the case in django 1.5.1

I've noticed this error when using workers that run the django code (using gearman).

To reproduce:

Set the timeout to low value by editing /etc/mysql/my.cnf
add the following under [mysqld]

wait_timeout    = 10
interactive_timeout = 10

Then 

{{{
% python manage.py shell

>>> # access DB 
>>> import django.contrib.auth.models
>>> print list(django.contrib.auth.models.User.objects.all())
>>> import time
>>> time.sleep(15)
>>> print list(django.contrib.auth.models.User.objects.all())
}}}

Now you get the error.

Simple solution I found on the web is to call django.db.close_connection() before the access

{{{
>>> import django.db
>>> django.db.close_connection()
>>> print list(django.contrib.auth.models.User.objects.all())
}}}
works ok."	Bug	closed	Database layer (models, ORM)	1.6	Release blocker	wontfix	mysql	Tim Graham victorgama	Accepted	1	0	0	1	0	0
