A Node.js service behind an ALB returns a steady trickle of 502s under normal load, with no app errors at all.

AdvancedTroubleshooting5xx errors
Answer

Likely causes → A keep-alive race. Node's server.keepAliveTimeout defaults to 5 s; the ALB keeps idle connections for 60 s. Node closes an idle socket just as the ALB sends a new request on it, and the ALB returns 502.

Diagnose → ALB logs show 502 with target_processing_time near zero and error_reason such as TargetResponseError or a connection reset, while the app logs nothing for those requests.

Fix →

server.keepAliveTimeout = 65_000;   // greater than ALB idle timeout
server.headersTimeout  = 66_000;   // must exceed keepAliveTimeout

Same rule for gunicorn (--keep-alive), nginx and others: the backend's keep-alive must be longer than the LB's idle timeout.

Prevent → A standard service template with these values set, and a dashboard that splits HTTPCode_ELB_5XX from HTTPCode_Target_5XX.

All Real-World Interview questions Roadmap: Interview readiness

More on 5xx errors