Gunicorn [CRITICAL] WORKER TIMEOUT: what it means and how to fix it
Gunicorn's master killed a worker that sent no heartbeat for longer than --timeout, 30 seconds by default. With the default sync worker that means one request ran too long. Move the slow work out of the request, use gthread workers for slow I/O, load heavy models at start with --preload instead of in the first request, and raise --timeout only for the app that needs it.
By Livops team, the people who build and run LivopsUpdated
What the log shows when a worker runs out of time in the middle of a request, with Gunicorn’s default sync worker:
[CRITICAL] WORKER TIMEOUT (pid:42)
[ERROR] Error handling request GET /report
Traceback (most recent call last):
...
File ".../gunicorn/workers/base.py", line ..., in handle_abort
sys.exit(1)
SystemExit: 1
[INFO] Worker exiting (pid: 42)
[INFO] Booting worker with pid: 57
The SystemExit: 1 traceback is Gunicorn stopping the worker, not your code failing. This page explains what the master process is doing, lists the causes from the most common with the exact flags that fix each one, shows how to tell it apart from Worker failed to boot and from an out-of-memory kill, and says how to change the timeout on Livops.
What does the error mean?
Gunicorn’s master process forks workers and watches each one through a heartbeat file. A worker that does not update it within --timeout seconds, 30 by default, is considered silent and is killed and restarted[1]. Idle workers keep updating the heartbeat while they wait for requests[1], so a timeout means the worker was busy with something that did not let it get back to its loop.
What happens next is in Gunicorn’s source. The master logs WORKER TIMEOUT (pid:N) and sends the worker SIGABRT; if the worker is still there at the next check, it sends SIGKILL[2]. On SIGABRT the worker calls the worker_abort hook and exits with sys.exit(1)[3], which is the traceback above. The master then boots a new worker to keep the count[2].
What the visitor gets: 500, 502 or 504
- 500. In a sync worker, if the response had not started yet, Gunicorn catches that exit, logs
Error handling requestand writes a500 Internal Server Errorto the client before the worker exits[4][3]. - 502. If the response had already started, the worker closes the connection instead[4], and a worker killed with
SIGKILLanswers nothing at all. The proxy in front sees a connection closed without a full answer and reports 502 Bad Gateway. - 504. If the proxy’s own timeout is shorter than Gunicorn’s, the proxy gives up first and answers 504 while the worker is still busy.
Not the same as “Worker failed to boot”
Worker failed to boot means importing your app raised an exception: the worker exits with code 3, and the master shuts the whole server down with Reason: Worker failed to boot.[2]. After a WORKER TIMEOUT the master keeps running and boots a replacement[2]. Read the lines just above the message: a Python traceback from your own code ending in an exception like ModuleNotFoundError means a failed boot; WORKER TIMEOUT means a worker that took too long.
Causes, most common first
1. A request takes longer than the timeout
The default sync worker handles one request at a time[6], and while it runs your view it does not update its heartbeat. A report that queries for a minute, a CSV export, an image or PDF generated in the request, a call to a slow external API or a language model: anything past 30 seconds is killed.
With the sync worker, the request is the one named in Error handling request right after the timeout[4][3]. Then, in order of preference:
- Move the work out of the request. Put the job on a queue, answer at once, and let a separate background process do it. The page polls, or the user is notified when it is done.
- Make it faster. An index for the query, a smaller page, and a timeout on the outgoing HTTP call shorter than Gunicorn’s, so your code fails with a clear error instead of being killed.
- Raise the timeout for this app. Gunicorn’s own advice for a worker timeout is to increase it or investigate slow requests[8]:
.venv/bin/gunicorn app:app --timeout 120
The settings reference says the default of thirty seconds should generally suffice, and to set it noticeably higher only if you are sure of the repercussions for sync workers[1]: a worker held for 120 seconds serves no one else for 120 seconds. --timeout 0 disables timeouts for all workers entirely[1], so a stuck worker is never replaced. Avoid it.
2. Sync workers blocked on I/O: use threads
Sync workers assume your app is CPU or network bound and avoids indefinite blocking operations; Gunicorn recommends async workers for long blocking calls such as external APIs and slow databases, and for streaming, long polling and WebSockets[6]. Two options, the first with no code changes:
# a thread pool in each worker
.venv/bin/gunicorn app:app -k gthread --workers 2 --threads 4
# greenlets: needs gevent installed (pip install "gunicorn[gevent]")
.venv/bin/gunicorn app:app -k gevent --worker-connections 1000
With gthread, threads can extend request time beyond the worker timeout while the worker keeps notifying the master[6]. For any worker class other than sync, the timeout only means the worker process is still communicating; it is not tied to the length of one request[1]. Setting --threads above 1 with the sync worker switches to gthread on its own[1]. gevent handles thousands of connections, but may need patches for some libraries, such as psycogreen for Psycopg, and does not suit code that relies on blocking behaviour[6].
An ASGI app such as FastAPI needs an ASGI worker class instead; Gunicorn’s design page lists them[6]. Threads do not make CPU-heavy work faster: a request that computes for 90 seconds still takes 90 seconds, so for that, go back to cause 1.
3. A model or cache is loaded in the first request
A common pattern to make the start faster is to load a machine learning model, a large file or a cache “lazily”, the first time a request needs it. That moves the load into a request, where the timeout applies: if loading takes 40 seconds, the first request after every worker start is killed, and the next worker starts the same way.
Load it at start instead. In Gunicorn’s current source, the worker loads your app before it enters its request loop, and its heartbeat file only starts counting with the first update from that loop[3][5][2], so loading at import is not cut off by --timeout. Better still, --preload loads the application code before the worker processes are forked[1]: the master does it once, before any worker starts[2], and the documentation says it can save RAM and speed up boot. The trade-off is that you can no longer reload the code by restarting workers[1].
.venv/bin/gunicorn app:app --preload --workers 2
A slow start has its own cost on a platform: until a worker is serving, nothing answers on the port. On Livops a new version that does not answer within a minute fails the deploy (see below).
4. The worker was killed for memory
A worker the kernel kills for using too much memory dies from SIGKILL, and Gunicorn logs it as[2]:
[ERROR] Worker (pid:42) was sent SIGKILL! Perhaps out of memory?
Look at the line before it. With WORKER TIMEOUT just above, the SIGKILL was Gunicorn’s own second step for a worker that did not exit after SIGABRT[2], and the cause is still a slow worker. With no timeout above it, suspect memory: the FAQ names the out-of-memory killer in cgroups-limited environments as a common culprit, and suggests dmesg | grep gunicorn to confirm[7]. Each worker holds its own copy of the app, so run fewer workers, use --preload to share what is loaded before the fork[1], or --max-requests to restart each worker after a number of requests, which limits the damage of memory leaks[1]. Gunicorn’s Docker guide lists the same three: fewer workers, --max-requests, a higher container memory limit[8].
5. The heartbeat itself blocks
The heartbeat involves a call on a temporary file that can block a worker for an arbitrary time if the directory is on a disk-backed filesystem[1]. If /tmp is not RAM-backed, the FAQ suggests a tmpfs mount and --worker-tmp-dir pointing at it[7]. This is rare next to causes 1 to 4; check it when timeouts hit fast endpoints.
How to find the slow code
Make the worker print where it was when it was stopped. worker_abort is called when a worker receives SIGABRT, which generally happens on timeout[1], and a gunicorn.conf.py in the working directory is read by default[9]:
# gunicorn.conf.py
import faulthandler
def worker_abort(worker):
faulthandler.dump_traceback(all_threads=True)
The next timeout prints the stack of every thread, down to the line of your code that was running. To reproduce it locally with the server’s settings, run one worker and call the slow endpoint:
.venv/bin/gunicorn app:app --workers 1 --timeout 30 --bind 127.0.0.1:8000
curl -i http://127.0.0.1:8000/report
gunicorn --print-config app:app prints the fully resolved configuration[9], a quick way to see which timeout and worker class are really in effect.
On Livops
- The start command Livops writes names no timeout and no worker count. For Flask with
gunicornin the requirements it is.venv/bin/gunicorn <module>:<app> --bind 0.0.0.0:3000; for Django,.venv/bin/gunicorn <project>.wsgi:application --bind 0.0.0.0:3000, aftermigrate. So Gunicorn’s defaults apply: the sync worker, a 30-second timeout, and one worker unlessWEB_CONCURRENCYsays otherwise[1]. - Change it with a variable. Gunicorn reads settings from the
GUNICORN_CMD_ARGSenvironment variable, and only flags on the command line take priority over it[9]. The command above sets neither, so a variable in the service’s Variables section is enough, for exampleGUNICORN_CMD_ARGS=--timeout 120 -k gthread --threads 4. New values take effect on the next deploy; to apply them now, restart the service. - Or write the start command yourself.
startinlivops.jsonis applied when the project is created; after that, the start command is changed in the project’s settings. The block below shows the form. - Slow jobs can move to a worker. A
workerservice is an always-on background process with no public URL, such as a queue consumer, and it receives databases and shared variables like a regular service. The web app answers at once and the worker does the slow part. - Memory is named in the log. An app that uses more memory than its plan allows is stopped, and the log says
Killedor exit code 137. Choose a bigger plan in the settings, or use less: fewer workers, or--preload. - The log shows the timeout. The Logs page shows the app’s output, and
livops logs <service> -ffollows it in the terminal. A new version that does not answer within a minute, for example because loading takes too long, fails the deploy asstart_failed.
{
"start": ".venv/bin/gunicorn app:app --preload --timeout 120 --bind 0.0.0.0:$PORT"
}
More in the docs: The app did not start, Variables and Frameworks and livops.json.
Questions
What is the default Gunicorn timeout?
30 seconds. A worker that has not updated its heartbeat for longer than that is killed and replaced. Change it with --timeout or -t on the command line, timeout in gunicorn.conf.py, or the GUNICORN_CMD_ARGS variable. 0 turns the timeout off for every worker, so a stuck worker is never replaced.
Is WORKER TIMEOUT the same as Worker failed to boot?
No. Worker failed to boot means importing your app raised an exception: the worker exits with code 3 and the master shuts the server down. WORKER TIMEOUT means a worker stayed busy too long: the master kills that worker, keeps running and boots a new one. The first is fixed in your code or configuration, the second by making the slow work shorter or the timeout longer.
Why does the log say Perhaps out of memory right after WORKER TIMEOUT?
Gunicorn first sends a timed-out worker SIGABRT. If the worker is still there at the next check, it sends SIGKILL, and every worker that dies from SIGKILL is logged as was sent SIGKILL! Perhaps out of memory? In that order the SIGKILL came from Gunicorn itself. The same line with no WORKER TIMEOUT before it points at the kernel's out-of-memory killer.
Should I just set a much higher timeout?
Only for an app where long requests are expected, and only as high as the slowest legitimate request. A sync worker serves one request at a time, so a worker held for two minutes serves nobody else for two minutes. Moving the slow job to a background process fixes the cause; a higher timeout only gives it more room.
Do gthread or gevent workers get WORKER TIMEOUT?
Less often. For worker classes other than sync, the timeout only means the worker process has stopped communicating with the master; it is not tied to how long one request takes. A gthread worker keeps notifying the master while its threads handle long requests. A worker whose whole process stops responding is still killed.
How do I raise the timeout on Livops without changing the start command?
Add a variable named GUNICORN_CMD_ARGS with the value --timeout 120 in the service's Variables section. Gunicorn reads it, and the start command Livops writes for Flask and Django sets no timeout of its own, so the variable applies. New values take effect on the next deploy, or at once if you restart the service.
Sources
- Gunicorn — Settings (gunicorn.org). Checked .
- Gunicorn source — gunicorn/arbiter.py (raw.githubusercontent.com). Checked .
- Gunicorn source — gunicorn/workers/base.py (raw.githubusercontent.com). Checked .
- Gunicorn source — gunicorn/workers/sync.py (raw.githubusercontent.com). Checked .
- Gunicorn source — gunicorn/workers/workertmp.py (raw.githubusercontent.com). Checked .
- Gunicorn — Design (gunicorn.org). Checked .
- Gunicorn — FAQ (gunicorn.org). Checked .
- Gunicorn — Docker (gunicorn.org). Checked .
- Gunicorn — Configuration overview (gunicorn.org). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Python appRelated
- Gunicorn "Worker failed to boot": what it means and how to fix itGunicorn's worker could not load your application, so the master process shut down. The cause is the Python traceback printed just above the message: most often a missing package or variable, or a wrong module:variable path in the gunicorn command. Fix what the traceback names and the workers boot.
- 502 Bad Gateway after deploying: what it means and how to fix itThe proxy in front of your app reached for it and got no valid answer: nothing was listening on the port it tried, or the process closed the connection mid-request. After a deploy that is almost always one of five things: the app listens on the wrong port or on 127.0.0.1, it crashed on start, it was still starting, it ran out of memory, or the proxy points at the wrong port. The app's own log says which.
- gunicorn: command not found (or uvicorn: command not found): how to fix itgunicorn: command not found, uvicorn: command not found and gunicorn: not found mean the shell looked for the command on PATH and did not find it, so the start ends with exit code 127. Gunicorn or Uvicorn is not in requirements.txt, or it was installed into a virtual environment or a --user folder whose bin is not on PATH. Add it to requirements.txt and start it through the environment's own Python: .venv/bin/python -m gunicorn or .venv/bin/python -m uvicorn.
- Django hosting in 2026: how to deploy a Django app, and whereFor most Django apps, a platform that deploys from Git is the right pick: Render and DigitalOcean App Platform are the simplest fixed monthly prices, Fly.io is the cheapest in dollars, Railway bills by usage, and a VPS is for when you want root. Livops fits Django apps whose users are in Uzbekistan, at 39 credits a month. Below: prices and free tiers side by side, a Django deployment checklist, and how to host a Django project on Livops.
- Flask hosting in 2026: how to deploy a Flask app, and whereA Flask app in production runs on a WSGI server such as Gunicorn, never on flask run, and is told it sits behind a proxy. On Livops a repository with app.py and requirements.txt that lists gunicorn starts on Gunicorn from a push, for 39 credits a month (39,000 so'm). Here is how Render, Railway, Fly.io and a VPS compare.
- FastAPI hosting in 2026: how to deploy a FastAPI app, and whereA FastAPI app in production runs on Uvicorn without --reload, listens on 0.0.0.0 and the platform's port, trusts the proxy's headers and runs its migrations before it starts. On Livops a repository with main.py and requirements.txt starts on Uvicorn from a push, for 39 credits a month (39,000 so'm). Here is how Render, Railway, Fly.io and a VPS compare.