🔄 Fix a Long-Polling Request Piling Up Behind a Proxy Timeout
A long-polling request deliberately holds the connection open until the server has new data to send, sometimes for 30–60 seconds, but any reverse proxy sitting in front of the app (nginx, a load balancer, a corporate gateway) has its own default upstream read timeout — if that timeout is shorter than the poll duration, the proxy kills the connection first, the browser reports a generic network error, and the client’s retry logic immediately opens another long poll that hits the exact same timeout again.
🔎 The Problem
Client-side timeline: t=0s Ajax long-poll request sent t=30s nginx proxy_read_timeout fires, connection reset t=30s XHR onerror fires, retry logic reopens the poll t=60s same proxy timeout fires again (repeats indefinitely, server never got to actually answer)
✅ Fix: Align the Poll Duration With the Proxy’s Actual Timeout
- Raise
proxy_read_timeout(or the equivalent on whatever reverse proxy sits in front) to comfortably exceed the long-poll’s maximum hold duration, with margin for network jitter. - Alternatively, shorten the server-side poll’s own max wait time to safely undercut the proxy’s existing timeout, so the server always responds (even with an empty ‘no new data yet’ result) before the proxy gets a chance to cut the connection.
- Have the client distinguish a proxy-timeout reset from a genuine server error in its retry logic, and back off briefly before reopening the poll instead of hammering the same timeout in a tight loop.
A long-polling request that keeps dying at the same elapsed time isn’t a flaky connection — it’s a proxy timeout that was never told how long the poll actually needs.




