django-celery: OperationalError: (2006, 'MySQL server has gone away')
When ever i restart my MySql celeryd and celerycam throw OperationalError: (2006, ‘MySQL server has gone away’) .
Traceback (most recent call last):
File "/home/webapp/webapp/../vendor/djcelery/schedulers.py", line 204, in sync
with commit_on_success():
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/webapp/webapp/../vendor/djcelery/db.py", line 56, in commit_on_success
with transaction.atomic(using):
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 280, in __enter__
connection.set_autocommit(False)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 333, in set_autocommit
self._set_autocommit(autocommit)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 460, in _set_autocommit
self.connection.autocommit(autocommit)
OperationalError: (2006, 'MySQL server has gone away')
Is it a bug ?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 24 (5 by maintainers)
Commits related to this issue
- Fix for #359 MySQL-OperationalError When the database connection dies (database server crash), the database scheduler of djcelery doesn't close the broken connection for its scheduler update calls. E... — committed to ufgstores/django-celery by trunneml 9 years ago
- don't catch database exceptions and ignore them celery/django-celery#359 When the connection to the database disappears, should either implement reconnection logic or fail hard. This change makes th... — committed to chrono/django-celery by chrono 8 years ago
- Fix for #359 MySQL-OperationalError When the database connection dies (database server crash), the database scheduler of djcelery doesn't close the broken connection for its scheduler update calls. E... — committed to opendatasoft/django-celery by trunneml 9 years ago
- Fix for #359 MySQL-OperationalError When the database connection dies (database server crash), the database scheduler of djcelery doesn't close the broken connection for its scheduler update calls. E... — committed to opendatasoft/django-celery by trunneml 9 years ago
- Fix for #359 MySQL-OperationalError (#370) When the database connection dies (database server crash), the database scheduler of djcelery doesn't close the broken connection for its scheduler update c... — committed to celery/django-celery by trunneml 8 years ago
👍
I can update, that this is not an issue of
django-celery
project. I encounter this with Django 1.8.13 and Celery 3.1.23, not usingdjango-celery
at all. To get rid of the error, i force ainside my Celery job before starting a possibly-long-running process. Django then re-opens the connection on the nearest database request. Another workaround can be implementing a decorator, that would attempt to execute a function and catch the “MySQL server has gone away” exception. If caught, then close the connection and try again. I use this approach to re-establish lost sftp connections, and i think this should work for reconnecting to MySQL.
In case it helps anyone else, one workaround for this is to disable Django’s persistent connections by setting ‘CONN_MAX_AGE’ to zero in the django settings.py file.