question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OperationalError: (2006, 'MySQL server has gone away')

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
abhijo89commented, Aug 26, 2015

👍

2reactions
vakorolcommented, Jun 17, 2016

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 using django-celery at all. To get rid of the error, i force a

django.db.connection.close()

inside 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL error 2006: mysql server has gone away
This generally indicates MySQL server connectivity issues or timeouts. Can generally be solved by changing wait_timeout and max_allowed_packet ...
Read more >
"MySQL server has gone away" error - Solution(s)
The MySQL server has gone away error, which means that the MySQL server (mysqld) timed out and closed the connection. By default, MySQL...
Read more >
How do I fix the error "Mysql Server has gone away"? FAQ
The MySQL server has gone away (error 2006) has two main causes and solutions: Server timed out and closed the connection. To fix,...
Read more >
B.3.2.7 MySQL server has gone away
The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. In...
Read more >
python - Error 2006: MySQL server has gone away
I looked in the uWSGI log, and found the following: sqlalchemy.exc.OperationalError: (OperationalError) (2006, 'MySQL server has gone away') ' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found