Troubleshooting guide
Gunicorn WORKER TIMEOUT: causes and how to fix it
Gunicorn killed a worker that did not check in within its timeout. Usually, one request blocked a sync worker for too long.
3 min read10 sectionsUpdated
On this page
# How often, and when?
journalctl -u gunicorn --since "1 hour ago" | grep -E 'WORKER TIMEOUT|SIGKILL|Booting'
# Upstream timing in Nginx (requires $upstream_response_time in log_format)
awk '$NF > 25' /var/log/nginx/access.log | tail
# Current workers and memory
ps -o pid,rss,etime,cmd -C gunicorn
# Dump a Python stack from a live worker (py-spy)
sudo py-spy dump --pid WORKER_PIDFixes
Set a timeout on every outbound call. Move long work into a task queue. Use gthread with threads for I/O-heavy applications, or uvicorn.workers.UvicornWorker for async. Size workers at around 2 x cores + 1 as a starting point, within available memory. Use --max-requests with jitter to recycle workers and contain slow leaks. Only raise --timeout for known routes that truly require it, and consider serving those separately.
Timeouts need to line up
The whole chain should agree. If Nginx's proxy_read_timeout is 60 seconds and Gunicorn's timeout is 30, users get a 502 at 30 seconds when the worker dies. If reversed, Nginx gives up first with a 504 while the worker keeps running on a request nobody wants. Set the outermost timeout longest, then have each inner layer give up earlier. Your database statement timeout should be shortest of all. With this ordering, a slow query fails cleanly with an error you can handle, rather than killing a worker.
Catch it automatically
APM records the slow request and where its time went, even if the worker later died. Alert on worker restarts per minute, and compare with p99 latency. See OpenTelemetry for Django or for Flask to instrument it.
What happens to the request?
It is aborted, and the proxy usually returns a 502 to the user.
Which worker class should I use?
gthread for typical I/O-bound WSGI apps, and uvicorn workers for ASGI.
Why do timeouts happen during startup?
Slow app loading can exceed the timeout. Reduce import-time work or raise the startup allowance.
Related reading
- 408 Request Timeout: causes and how to fix it: Understand 408 Request Timeout: slow client uploads, idle keep-alive connections and proxy settings, and how it differs from a 504 Gateway Timeout.
- 504 Gateway Timeout: causes and fixes: What causes 504 Gateway Timeout errors, how timeouts stack across CDN, load balancer and Nginx, and how to find and fix the slow request.
- MySQL server has gone away: causes and how to fix it: Fix MySQL error 2006 server has gone away: idle timeouts, oversized packets, server restarts and connection pools holding connections that have died.
- ERR_CONNECTION_RESET: causes and how to fix it: Fix ERR_CONNECTION_RESET: crashed backends, firewalls and antivirus resetting traffic, MTU problems and keep-alive races, for both visitors and site owners.
- Kubernetes readiness probe failed: how to fix it: Fix Kubernetes readiness and liveness probe failures: slow startup, wrong ports, overloaded health endpoints and dependency checks that cause cascading outages.
- ERR_HTTP2_PROTOCOL_ERROR: causes and how to fix it: Fix ERR_HTTP2_PROTOCOL_ERROR in Chrome: invalid response headers, crashed backends behind HTTP/2 proxies, buffer limits and antivirus interference.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.