Gunicorn logs `[CRITICAL] WORKER TIMEOUT (pid:42)` and requests fail with 502 from the load balancer.
AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer
Likely causes → A request took longer than gunicorn's --timeout (30s default) on a sync worker, usually a slow downstream call without a timeout, or CPU-bound work.
Diagnose → Correlate timeouts with endpoints in access logs; py-spy dump on a worker during a slow request.
Fix → Add timeouts to outbound calls, move long jobs to a background queue, use gthread or async workers for I/O-bound handlers, and raise --timeout only if the work is legitimately long.
Prevent → Latency histograms per endpoint and timeouts on all external calls.
More on Concurrency, async, tests, services & containers
`RuntimeError: asyncio.run() cannot be called from a running event loop` in a Jupyter notebook or inside an async framework.Intermediate`RuntimeWarning: coroutine 'fetch' was never awaited` and nothing happens.BeginnerAn asyncio health-checker is no faster than a sequential loop.Advanced`Task was destroyed but it is pending!` at shutdown.Advanced`OSError: [Errno 24] Too many open files` from an asyncio scanner with 20,000 targets.IntermediateA `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.Intermediate