Skip to content

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

Key points

  • Sync workers handle one request at a time.
  • Raising --timeout hides slow requests.
  • Blocking calls with no timeout are the top cause.
  • A 502 from Nginx is what users see.

What it means

Each worker notifies the master periodically. If a worker goes silent for --timeout seconds, 30 by default, the master kills and replaces it, logging WORKER TIMEOUT. With sync workers, a single long request prevents the check-in, so the request dies with its worker.

Common causes

  • Slow database queries.
  • Third-party calls with no timeout.
  • Big uploads or responses on sync workers.
  • CPU-bound work inside a request.
  • Memory swapping that stalls everything.
  • Slow app startup without --preload or a longer boot allowance.

Diagnose it

Find which requests were running at the moment of the kill.

bash
# 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_PID

Fixes

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.

Frequently asked questions

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.

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.