The stream dies after 60 seconds

A stream that dies on the same second is a timeout. Default values in nginx, ALB, Cloudflare, Heroku and Envoy, and why a heartbeat is safer.

What it means

Events arrive, then the connection closes on the same second every time, usually the sixtieth. That is not a network failure but a configured timeout.

How to fix it

Raise the timeout on every proxy you control.

nginx. proxy_read_timeout defaults to 60 s, counted between two reads from the backend, not from the start. An event every ten seconds keeps the stream alive; a quiet minute kills it.

location /events {
    proxy_pass http://app;
    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    send_timeout 3600s;
}

proxy_read_timeout covers reads from the backend, proxy_send_timeout writes to it, send_timeout writes to the client; all default to 60 s.

Kubernetes ingress-nginx. Set the timeouts as annotations.

nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"

AWS ALB. idle_timeout.timeout_seconds defaults to 60.

aws elbv2 modify-load-balancer-attributes \
  --load-balancer-arn <arn> \
  --attributes Key=idle_timeout.timeout_seconds,Value=3600

Apache. ProxyTimeout inherits Timeout, 60 s in 2.4. Set ProxyTimeout 3600.

Envoy. The route timeout defaults to 15 s and caps the whole response, so a heartbeat does not help. Set 0s and rely on stream_idle_timeout (5 minutes).

Cloudflare. Returns 524 after 125 s without data from the origin. Only Enterprise can raise it (to 6000 s).

Heroku. The timeouts are fixed at 30 s to the first byte, then a 55-second window between bytes (H12, H15, H28).

gunicorn. The 30 s timeout kills a sync worker busy with a long stream. Use gevent or eventlet workers, or --timeout 0.

uvicorn. There is no request timeout; --timeout-keep-alive (5 s) covers only idle keep-alive connections.

A heartbeat beats the setting

Corporate proxies, home routers and mobile carriers have timeouts you cannot see, and RFC 9112 § 9.5 lets any of them close an idle connection. So never go quiet. An SSE line starting with a colon is a comment the client ignores.

const heartbeat = setInterval(() => res.write(': ping\n\n'), 15_000);
req.on('close', () => clearInterval(heartbeat));

Send it every 15 s, not every 59, because some timeouts are under a minute. It costs eight bytes.

A heartbeat beats only idle timeouts. Total-duration limits (Envoy's route timeout, many API gateways) must be raised by hand.

Set the client's reconnect delay; EventSource applies it.

retry: 3000

Telling a timeout apart from everything else

What you see What it is
Cut on the same second every time a timeout on one of the proxies
Cut at a random time, every client at once the application restarted or crashed
Cut at a random time, one client that client's network
Data arrives in a batch, then a cut buffering plus a timeout

WebSocket breaks the same way, as close code 1006.

See it on your own traffic

Solpuga shows the request's start time in Summary, every event with its arrival time to the millisecond, and Stream closed when it ends. A minute-long pause before each cut means an idle timeout. If events kept coming up to the cut, it is not that, so look for a total-duration limit or at the application. See Capture & Inspect Traffic for how Solpuga records a stream.

View in Solpuga

Tool for this page

SSE stream parserPaste a raw Server-Sent Events stream and see the events, ids, retry hints and framing mistakes.

Related