Forums

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

I am experiencing a strange problem with my web app. Every half-hour or so I am getting the OperationalError: (2006, 'MySQL server has gone away'). However, if I resave my wsgi.py file, the error disappears. And then appears again some half-an-hour later...

During the loading of the main page, my app checks a BOOL field in a 1x1 table (basically whether sign-ups should be open or closed). The only other MySQL actions are inserts into another small table, but none of these appear to be associated with the problem.

Any ideas for how I can fix this? I can provide more information as is necessary. Thanks in advance for your help.

We have a timeout on connections to the database so they don't keep piling up. So my guess is that you're making a connection to the database and then holding on to it with no code to re-connect if the connection is dropped. When you edit your wsgi file, your web app gets restarted and your app reconnects to the database, so the error goes away until the database drops your connection again.

Thanks, glenn! I have got it working now—turns out that I was confused about when/how many times certain portions of code run.