Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithStreamDeadline ¶ added in v0.5.0
func WithStreamDeadline(writeTimeout, streamStallTimeout time.Duration) func(http.Handler) http.Handler
WithStreamDeadline adjusts the PER-REQUEST write deadline so a streaming response is not severed by the connection-level http.Server.WriteTimeout.
In Go, WriteTimeout deadlines the whole connection rather than a single slow write, so an in-flight text/event-stream response is torn down mid-body when it elapses — no matter how healthily it is flushing. That is kdex-tech/host-manager#167: both production SSE surfaces sat in a permanent ~60s reconnect loop.
A writeTimeout of zero or less means the server has no write deadline, so there is nothing to adjust and this is a pass-through.
streamStallTimeout is the SEPARATE, much larger window an SSE response slides on. SSE is not exempt from bounding — it is bounded on its own terms. Clearing the deadline outright (the first #167 implementation) left a consumer that stops reading parked in Flush->conn.Write under TCP backpressure with nothing to cut it: the request context cancels on close, not on a stalled reader, so Linux TCP keepalive reaped it at ~2h11m where pre-#167 it died at writeTimeout. Nothing else in the repo covers that — ReadTimeout/ReadHeaderTimeout bound the request only, IdleTimeout bounds inter-request idle only, and there is no ConnState/LimitListener/TimeoutHandler — and each held connection pins a goroutine, an FD, the upstream connection and ReverseProxy's 32KB buffer. The design's rationale ("the cadence belongs to the backend") argues against a CADENCE-SIZED cap, not against any cap: at the 5m default a healthy stream runs unbounded at 20x the 15s keep-alive cadence of the affected backends, while a stalled one dies in minutes. Zero or less restores the cleared-deadline behavior for SSE, which is the documented escape hatch for a backend whose legitimate silence can exceed any window.
Types ¶
This section is empty.