Go SSE Streams Break Silently Due to HTTP/2 Headers and Default Timeouts
Server-Sent Events (SSE) in Go fail in two distinct ways before any application logic runs: first, because setting a Connection header is forbidden under HTTP/2 (RFC 9113), and second, because default server timeouts such as WriteTimeout and middleware context cancellation silently cut streams at 30 seconds. Both issues produce the same browser-side symptom — a net::ERR_HTTP2_PROTOCOL_ERROR and a reconnect loop — making the protocol appear at fault when the real cause is server configuration. A Go developer running SSE endpoints in production on Kubernetes traced both failures to a shared internal package that applied API-oriented defaults unsuitable for long-lived streams. The correct fix requires removing hop-by-hop headers entirely and overriding both the WriteTimeout and any context-cancelling middleware specifically for streaming paths. A related Go patch in August 2026 reinforced the same principle: a timeout only protects the connections it explicitly covers.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in