GunicornLinkerd

Gunicorn keepalive timeout causing intermittent 502s

warning
Connection ManagementUpdated Mar 5, 2025(via Exa)
How to detect:

Gunicorn's default idle connection timeout of approximately 2 seconds closes connections before upstream proxy or service mesh timeout expires. When proxy attempts to reuse a closed connection, it results in random 502 errors. Particularly affects Kubernetes deployments with service meshes like Linkerd.

Recommended action:

Configure Gunicorn keepalive timeout to exceed upstream proxy or service mesh idle timeout. Add 'keepalive = <value>' parameter to gunicorn_config.py, setting it higher than the upstream component's timeout (e.g., if Linkerd timeout is 10s, set keepalive to 15s or higher). This prevents premature connection closure.