-
Notifications
You must be signed in to change notification settings - Fork 79
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
DbConnectionsMiddleware and "Lost connection to MySQL server during query" #19
Comments
Hi!, I don't know if my problem is related... But I'm having too much I run dramatiq worker in two servers (with RabbitMQ as backend) and after 24 or 36 hours of running, my Sentry is flooded with 'MySQL server has gone away' and I must to restart the workers. Thanks!
|
Hi, Happy new year! I updated my dependencies Today
The same issue :( Thanks for your time!
|
This issue sounds like you're holding a connection to a MySQL server in a pool for long enough that the server times out the connection. This page has more information on the issue. The simplest way to fix this in a Django application (without touching the db) is probably to turn off connection pooling by setting the |
Thanks you @Bogdanp . I "fixed" my issue several months ago, using the workarround suggested by @brunabxs Let my say that I'm not using a connection pool with Django. Monitoring the MySQL DB I can see how the worker keeps the conecction alive (even when no tasks queued). When the connection is lost, the worker starts failing forever. I tried to find the reason by verifying the source code but I could not do it :( Thanks again! Greetings! |
@nachopro I just took a look at the Django source code and it appears things work differently than I initially thought. IMO, this is bad design on Django's part, but it looks like they expect you to iterate over and possibly close connections before and after every request (in our case task execution). I'll push a fix in a few minutes. The example @brunabxs gave is the appropriate way to fix this. |
OK, this should now be fixed in |
@nachopro let me know if |
@Bogdanp Yes, it's working great 🌅🌞 |
Awesome! Sorry it took so long to fix. |
Do not worry. Dramatiq is a great piece of software and supports many different providers. It is impossible to be aware of everything. Thank you very much and especially to @brunabxs , who proposed the solution. |
FYI, I have spent over half a day trying to figure out why I had the "lost connection" issue happening for me on Postgres. The exceptions were happening in The underlying reason turned out to be the config: DRAMATIQ_BROKER = {
...
"MIDDLEWARE": [
"django_dramatiq.middleware.DbConnectionsMiddleware", # AdminMiddleware MUST BE AFTER
"django_dramatiq.middleware.AdminMiddleware",
],
} @Bogdanp, do you think it's worth mentioning in the README? |
Hi,
I am using DbConnectionsMiddleware and I am still having problems if two tasks are processed and MySQL closes the connection between these two executions.
I wrote a test to illustrate this example:
models.py
tests.py
I think the problem occurs because DbConnectionsMiddleware closes django db connections only:
I think it needs also to close old connections:
Am I doing something wrong or what I've proposed makes sense?
The text was updated successfully, but these errors were encountered: