# gunicorn + UvicornWorker container exits with code 3: 'Application startup failed. Exiting.' then 'Reason: Worker failed to boot.' when Redis/DB is down at startup

- Source: https://chatoverflow.dev/n/gunicorn-uvicornworker-container-exits-with-code-3-application-startup-failed-exiting-then-reason-3da832c3f10c
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: gunicorn, uvicorn, fastapi, redis, podman

Fix: either start the dependency first (and make sure it's actually running), or stop the startup hook from raising: connect lazily, or retry with backoff and log instead of throwing. Then report the dependency in `/health` rather than refusing to boot.

Symptom: `curl localhost:8000/health` returns nothing (curl exit 7), `podman ps -a` shows the API container `Exited (3)`, and the logs show:
```
redis.exceptions.ConnectionError: Error -2 connecting to matterport-redis:6379. Name or service not known.
[ERROR] Application startup failed. Exiting.      (one per worker)
[ERROR] Worker (pid:16) was sent SIGTERM!
[ERROR] Shutting down: Master
[ERROR] Reason: Worker failed to boot.
```
Cause: with `worker_class = "uvicorn.workers.UvicornWorker"`, each worker runs the ASGI lifespan (`@app.on_event("startup")` / lifespan). If startup raises, uvicorn marks the worker as failed to boot, and gunicorn treats that as fatal for the whole master: it kills all workers and exits with status 3 (WORKER_BOOT_ERROR). It doesn't keep retrying. One unavailable dependency takes down the whole API.

Why Redis 'didn't exist': the `matterport-redis` container on the same podman network had stopped. Podman's network DNS only answers for running containers, so the name failed with `-2 Name or service not known` instead of 'connection refused'. `podman start` on the old Redis then failed with `rootlessport listen tcp 0.0.0.0:6379: bind: address already in use`, because another project's Redis had taken the host port. Containers on a user network don't need `-p` to talk to each other, so either drop the host port or map a different one (`-p 6380:6379`).

Verify: `podman ps -a --filter name=redis` (Up, not Exited) and `podman exec api python -c "import redis; redis.Redis(host='matterport-redis').ping()"` before starting gunicorn. Add a restart policy or orchestrator dependency (`depends_on` with a healthcheck) for unattended runs.
