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.
More on 5xx errors
Right after a release, 500s spike to 8% and logs show `java.lang.NullPointerException` in a new code path.BeginnerLong-running report exports fail with "504 Gateway Time-out" from the ALB at exactly 60 seconds.Beginnernginx logs "upstream prematurely closed connection while reading response header from upstream" and users get 502.IntermediateEvery deploy causes 10–20 seconds of 502s from the ALB, even with a rolling update.IntermediateThrough Istio, clients get "503 upstream connect error or disconnect/reset before headers. reset reason: connection failure".IntermediateAPI Gateway returns "502 Bad Gateway" and the logs say "Execution failed due to configuration error: Malformed Lambda proxy response".Beginner