fix: don't warn on routine client-disconnect write/flush errors - #2589
Merged
Conversation
go_sapi_flush logged every ResponseController.Flush() error with the same "not a flusher" message, even when the writer clearly supports Flush but the call failed for another reason (e.g. a client disconnect). Only use that message for http.ErrNotSupported and log the real error otherwise.
A client disconnecting mid-flush is routine and not actionable, unlike the "not a flusher" misconfiguration case.
Same event as go_ub_write's "write error" (client disconnect), so log it at the same level for consistency. Flatten the nested if/else into early returns.
Caddy (streaming.go: "backConn write failed", "streaming error") and Mercure (subscribe.go: "Failed to write comment", "Connection closed by the client") both log repeated per-write streaming failures at debug, reserving warn for one-off actionable problems. Match that: a client disconnecting mid-response is routine and can repeat on every write of a request, so it doesn't belong at warn. Only the "not a flusher" misconfiguration case stays at warn. Also avoid computing the message/level before knowing whether the logger is even enabled for it.
dunglas
marked this pull request as ready for review
August 4, 2026 19:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While investigating #2588, found two related logging bugs around client disconnects.
go_sapi_flushlogged everyResponseController.Flush()error under the same message:That message is only accurate for
http.ErrNotSupported. A plain disconnect/write error (e.g. an aborted HTTP/2 stream) got mislabeled the same way, misleading and able to mask the real cause when triaging issues shaped like #2588.Also reconsidered the log level.
go_ub_write's equivalent "write error" was logged at warn, so the new "flush error" branch was first matched to it. But a client disconnecting mid-response is routine, and both writes and flushes happen in a loop, so a single request can log this dozens or hundreds of times, one per write/flush call after the disconnect. Not warn-worthy.Checked how the two other Caddy-family projects here handle this same class of error:
streaming.go): "backConn write failed", "response flush", "streaming error" - all logged at debug.subscribe.go): "Failed to write comment" (per-write, in a loop) and "Connection closed by the client" are debug; only one-off lifecycle events like "Subscriber disconnected" are info.Matched that convention:
go_ub_write's "write error" -> debug (was warn).go_sapi_flush's "flush error" -> debug (routine disconnect), correctly separated from "not a flusher".go_sapi_flush's "not a flusher" -> stays warn (real misconfiguration, not a per-request occurrence).This only fixes logging, not the segfault. I was not able to reproduce the crash reported in #2588 (see comment on the issue).
Test plan
go build ./...go vet ./...go test -run "TestConnectionAbort|TestLog" ./...