Repository navigation
Closed
Description
Issue Details
The document for write_idle specifies
responses that pause between writes (like server-sent events), are not affected as long as each write makes progress.
However, it's only true for h1 and h3 requests, since both set the write deadline on the underlying connection and stream respectively.
For h2, this will cause onWriteTimeout to fire
which will cause h2 internal stream errors
It can be reproduced with the following steps, (idle timeout reduced to 2s)
Caddyfile
{
local_certs
skip_install_trust
servers :443 {
timeouts {
write_idle 2s
}
}
}
https://127.0.0.1 {
reverse_proxy 127.0.0.1:81
}
Backend
package main
import (
"fmt"
"net/http"
"time"
)
func sseHandler(w http.ResponseWriter, r *http.Request) {
// 1. Set SSE response headers
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
w.Header().Set("Access-Control-Allow-Origin", "*")
// 2. Initialize ResponseController for explicit flushing
rc := http.NewResponseController(w)
// 3. Stream data periodically until client disconnects
ctx := r.Context()
ticker := time.NewTicker(7 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
fmt.Println("Client disconnected")
return
case t := <-ticker.C:
fmt.Fprintf(w, "data: Server time is %s\n\n", t.Format(time.RFC3339))
if err := rc.Flush(); err != nil {
fmt.Println("Error flushing data:", err)
return
}
}
}
}
func main() {
http.HandleFunc("/events", sseHandler)
fmt.Println("SSE Server running on http://localhost:81/events")
// Bind specifically to localhost on port 81
if err := http.ListenAndServe("localhost:81", nil); err != nil {
fmt.Println("Error starting server:", err)
}
}
With curl -N https://127.0.0.1/events -k, we can observe one line of output before the h2 internal error.
data: Server time is 2026-10-03T03:22:26Z
curl: (92) HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)
Assistance Disclosure
No AI was used.
If AI was used, describe the extent to which it was used.
No response
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Default write_idle (v2.11.6) causes h2 streaming responses that are idle for 60s to fail[/-][+]write_idle (v2.11.6) causes h2 streaming responses that are idle for the specified duration to fail[/+]caddyhttp: bound flushes and keep write_timeout when clearing idle de…
caddyhttp: only bound HTTP/2 body reads in flight with the idle timeout
caddyhttp: only bound HTTP/2 body reads in flight with the idle timeout
caddyhttp: only bound HTTP/2 body reads in flight with the idle timeo…
caddyhttp: only bound HTTP/2 body reads in flight with the idle timeo…