Django with Gunicorn gives frequent [CRITICAL] WORKER TIMEOUTs on simple requests
I have been trying to deploy an app (no real users on this deploy yet). The deployment works, but some site requests that barely require any amount of back-end processing time (i.e. retrieve 1 model in the django admin without any calculated fields) will lead to Gunicorn timeouts. After a few seconds it will often work again, keep working for a while, and eventually go back to timeout's.
Suggestions are very much appreciated. I have 2 gunicorn workers and 2 replica's and I am the only user.
I am running it using docker with the following dockerfile
Where the entrypoint will do migrations and eventually run
21 Replies
Project ID:
45fb0a1b-efd2-4699-81c8-16a885d8c33c
45fb0a1b-efd2-4699-81c8-16a885d8c33c
Update: I now also have requests hanging for 5 minutes before a definitive timeout.
had another user with the exact same problem on the same tech stack, their issue turned out to be incorrect database credentials, the database connection was hanging up then silently failing blocking all requests while doing so
I am using , and this can't explain why it does work sometimes right?
is that the environment variable you are using in code? because unless you are using a url database module django only accepts separate database credentials
show me the database stuff in your settings.py please
I am using django-environ
migrating the database, loading the fixtures, etc. works (I have a sleep 2 on startup to ensure database connection is ready, as recommended in another post).
And I can see the data in my admin panel if it does not time out.
sleep 3 is recommended, 2 seconds is pushing it because the max time for readiness does tend to exceed 2 seconds
I increased it to 5 to be on the safe side, but this won't resolve my timeouts 😅
theres some other piece of code somewhere that's blocking, I'd recommend adding verbose debug logging to find out at what point your app is locking up
Ok, will do that. Do you mean in Gunicorn or in Django or in my postgres service (or all of them) 🤔 ?
in django
I added debug logging, but I don't see anything in my logs when this happens.
The get request only shows after it keeps hanging for a while
something in your code is freezing and causing the request to take longer than 30 seconds
unless you have something that should take longer than 30 seconds?
It happens on arbitrary requests that do not take any significant amount of time (should not be even close to a second), and it does not happen locally nor on my PythonAnywhere hosted (test)server (that does not deploy with Docker) 🤔 .
railway runs your code as is, pythonanywhere is likely monkeypatching away some bugs in your code
I already put the gunicorn timeout on 60 to test if it eventually would finish (which it does not).
without an error or any logs to go off of theres not much i can help you with here unfortunately
did u find any fix to this issue since im also facing a similar issue
I did not, based on my logging it seems to be hanging on loading static files, which I am serving through
whitenoise
(6.6.0)
please reference the docs for whitenoise on how to properly configure it
@MIGHTY_MIDHUN I solved it eventually by moving my static files to a Google Cloud Storage bucket.