-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The old issue (2006, 'MySQL server has gone away') which have been fixed in 0.2.5 earlier but again came on 19th July 2020 #128
Comments
This issue appears to be MySQL specific, and affects all Django applications. Have a look at https://code.djangoproject.com/ticket/21597#comment:29 for some context and history. I haven’t come across an example of an elegant solution being used in any other Django projects. The overhead of pinging the database to keep the connection alive as proposed in #13 is probably not fair towards users of other, non-MySQL backends, and would interfere with connection poolers like pgbouncer. |
Thanks but since MySQL is also widely used with Django and our Django application is facing issue only with apscheduler. |
From the link to the upstream Django project issue #21597 shared above:
|
Thanks for reply but I don't understand how to do that. We are having the below steps: I have pasted the code which is just printing message and closing the connection object as you shared the comment link. When DB service is restarting then again same issue starting (2006, 'MySQL server has gone away') after every 10 sec and its even not calling the demo method even the DB service is available now. ` scheduler=BackgroundScheduler({'apscheduler.job_defaults.max_instances':'1','daemon':True, 'apscheduler.job_defaults.coalesce':'true'}) def demo(): ` |
Sorry this might not be very helpful, but re-opening database connections automatically after a DB server crash is not something that Django supports. You should probably be supervising the DB server process at operating system level, and restarting your web server automatically as well in case an unexpected DB crash occurs. If you are restarting the DB on a pre-determined schedule then it would probably make sense to stop the web server first, and then start it up again once the DB is available (otherwise, how would Django be able to service any HTTP client requests while the DB is down?). If you look through the related issues that have been logged in the Django project up stream then you will notice that there are many nuances that make a 'catch-all' solution quite difficult to implement. If you don't care and just want a quick fix, then it might be sensible to revert to an earlier version of django-apscheduler, or try to re-use elements of the old workaround that this project used to include: https://github.com/jarekwg/django-apscheduler/blob/d7dad0f7901291e1dae497082bf95fd3c214c0b2/django_apscheduler/models.py#L9-L35. |
Closing this issue as the example provided above should be sufficient for anyone wanting to re-implement the database pinging approach to detect when the database goes away. We might also consider trying: django.db import connection
connection.close() ...after every new job is scheduled if anyone encounters this issue under normal operating conditions (i.e. even if the database remains online and available). |
same issue which is mentioned in #13
but since the fix have been removed on 19th July 2020 now getting this issue.
Create a scheduler and add DjangoJobStore, and start it.
Add a job which will run in 5 minutes.
Restart the DB service.
Wait till 5 min.
Since the DB server is having some schedule restart this issue starts. On server after every 10 sec its keep checking the connectivity and throwing the error (2006, 'MySQL server has gone away')
even when DB server backs it keep in that error and not calling the next schedule.
The text was updated successfully, but these errors were encountered: