-
Notifications
You must be signed in to change notification settings - Fork 77
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
InterfaceError: connection already closed #106
Comments
I found this old issue in Celery that is perhaps helpful: celery/django-celery#121 Also this blog post: https://tryolabs.com/blog/2014/02/12/long-running-process-and-django-orm/ And one more lead: https://stackoverflow.com/a/37891165/3211027 |
Is the |
@Bogdanp yes it's in the correct order, my
I'm also now seeing this error around 50 times per hour: I currently have |
No, that setting should be fine (if a little inefficient). Re. the decoding error, are you using the Redis broker? If so, you should try upgrading to |
@Bogdanp Yep using Redis as the broker. I'll try that, thanks. Any clues about the |
I'm really not sure what it could be. I would probably start by making sure the clean up code in the connections middleware runs at the right time and there's nothing else that might be opening up connections after it and leaving them open. |
I don't actually use django_dramatiq but I just run into the same problem with plain Django + Dramatiq. Are you wrapping any DB calls in sync_to_async? Here's a standalone Django management command to recreate it:
While the above is running kill the connection in Postgres with the following:
Then it should start spitting out "connection already closed" errors. It seems like extra DB cleanup is needed for any async threads or it could be a Django bug? |
A fix seems to be to send
|
Thanks for this.
No, I'm not using any Django async functionality in my project. I tried putting My current (horrible) solution is to restart my worker process every 15 minutes! |
It could also be a regular thread somewhere (or running dramatiq with --threads x and non thread safe code). From what I understand sync_to_async is just a wrapper around an asyncio ThreadExecutor. |
I'm having the same issue. The funny part is it's only on our staging system. Production seems fine. This was a lift and shift extraction of a microservice. I've been working on getting it into production. No async code. We're using Settings
Only task running
|
@martyphee Is it easily reproducible or somewhat random? Do you have a high throughput of tasks? I'm also using Sentry and I wonder if that could be related. For extra context I'm averaging 20 tasks/second and it this issue usually appears after 24-48 hours. But it appears to be entirely random. |
@drpancake seems to consistently happen on our staging servers. The picture below are the task processors and each is now holding 64 connections. That will be the max they hold and we get into a situation where the connection pool, for the lack of a better description, freaks out and throws tons of errors saying This is the only job running and it only runs once per minute as a test. There is nothing else hitting it. It took about 24 hours to hit the 64/conn per pod. I restarted the pods yesterday morning. |
Interesting! Let me know if you make any breakthroughs. Perhaps you could try running the task more frequently to see if you hit the error sooner. As much as I detest it, I may have to move over to Celery at some point as it's at least battle-tested for a high throughput of tasks like my use case. |
FWIW, I'm having this problem with Celery and there's an issue about this here: celery/django-celery#121 Bummer to see dramatiq having this problem too. I was just thinking I could solve so many of precisely these kinds of issues by switching over. |
@mlissner That's disheartening to hear! I'm still using Dramatiq but I have a cron job that restarts the worker process every 15 minutes. Luckily for my use case tasks getting killed randomly is acceptable. |
Sigh...I've been seeing this as well 3 years later. I have 48 workers each with a thread servicing 100 or so requests. The task is very complex and brittle (in Production I can't let it fail) so looking for a simple way of creating a test task to simulate the issue. The problem never happens with 16 workers and I have pgbouncer in the mix too, so I am not even sure where to start. |
I'm pushing 500+ tasks per minute through Dramatiq as part of a Django app and occasionally (once every 1-2 days) I suddenly get hundreds instances of this error from the workers and the only way to fix it is to restart the worker process.
Sentry reports that it's triggered in both
before_process_message()
andafter_process_message()
when they both callTask.tasks.create_or_update_from_message()
.I have
CONN_MAX_AGE
set to0
and database connections are pooled via PgBouncer.Please let me know if I'm missing any other information.
The text was updated successfully, but these errors were encountered: