2

I am running a website on django 1.10, python3.4, mysqlclient, mysql5.5.

I have multiple management command running in the background for various tasks (like mail sending, updating tables) at different times. Recently, I have started seeing many Mysql gone away (Error 2006).

I tried to change the connection_timeout to be greater than max_connection age. That solved a small share of problem in which Error 2006 stopped to occur for a running function in most of the case but other cases are as it is and frequently seeing Error 2006.

In some cases, I tried using django.db.connection.close() before running a function or putting it in try - except loop. In those places, this error are not occuring anymore but then I cannot put this try-except loop in every function.

What is the root cause of this repeated error Mysql gone away? What are the different solution and what is the best solution so that I do not have to change much of my codes?

Other Variables:

We upgraded from django 1.7 to 1.10 and updated the mysqlclient package recently and the problem surfaced after that probably.

Just around the update, the traffic on our site also increased multiple times. Can that be a trigger?

sprksh
  • 2,204
  • 2
  • 26
  • 43

1 Answers1

0

As seen elsewhere, the problem can be either that your query is too long, or the server closed the connection due to inactivity. It depends a lot on the circumstances, but it seems that if you're not in the middle of a transaction (which would discard the second possibility), you can apply something similar to Hook available for automatic retry after deadlock in django and mysql setup

Marcos Dione
  • 556
  • 6
  • 13