HAProxy logs show `504` responses with termination state `sH--`.
IntermediateTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → HAProxy's termination flags read: first letter s = server-side timeout, second H = while waiting for response headers. So the backend accepted the request but didn't send headers within timeout server. (Compare cD = client-side timeout during data, SC = server refused the connection.)
Diagnose →
grep ' sH-- ' /var/log/haproxy.log | awk '{print $9, $NF}' | sort | uniq -c | sort -rn | head
# Tr (server response time) in the timers field shows how long the server took
Fix → Fix the slow backend, or raise timeout server for that backend only. Make sure the backend's own timeout is shorter so it fails cleanly instead of HAProxy cutting it.
Prevent → Learn the termination flags table; parse them into your log pipeline as fields and alert on s* timeouts per backend.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate