Repository navigation
caddyhttp: surface write timeout errors in access log - #7945
Merged
francislavoie merged 1 commit intoSep 4, 2026
Merged
francislavoie merged 1 commit into
francislavoie merged 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Caddy’s HTTP server access logging to surface client write failures (notably HTTP/1.x write timeout i/o errors) by adding a new write_error field, so logs no longer imply a successful response when the client received none.
Changes:
- Track and flush HTTP/1.x responses after handler completion (when duration ≥
WriteTimeout) to observe terminal write errors before access logging. - Extend access log emission to include a
write_errorfield when a terminal flush/write error is detected (excludinghttp.ErrHijacked). - Update existing logRequest tests/benchmarks for the new parameter and add a unit test for the
write_errorfield output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| modules/caddyhttp/server.go | Adds write-timeout flush observation and includes a new write_error access log field. |
| modules/caddyhttp/server_test.go | Updates existing logRequest tests/benchmarks for the new signature and adds coverage for emitting write_error. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
faiyazrahmann
force-pushed
the
fix-7938-access-log-write-timeout
branch
2 times, most recently
from
August 17, 2026 09:10
7fc15db to
1c0ac03
Compare
WeidiDeng
requested changes
Aug 17, 2026
faiyazrahmann
force-pushed
the
fix-7938-access-log-write-timeout
branch
from
August 17, 2026 12:54
1c0ac03 to
d50474c
Compare
steadytao
requested changes
Sep 2, 2026
faiyazrahmann
force-pushed
the
fix-7938-access-log-write-timeout
branch
from
September 3, 2026 10:32
b8fad79 to
6b741c0
Compare
steadytao
approved these changes
Sep 4, 2026
steadytao
left a comment
Member
There was a problem hiding this comment.
I am happy with this now. LGTM.
Member
|
I will let you review before merge @WeidiDeng - please take your time. |
WeidiDeng
requested changes
Sep 4, 2026
Access logs recorded status 200 and full resp_headers on write timeouts, even though the client never received a response. Adds a write_error field with the actual flush error, gated to HTTP/1.x requests past the configured write timeout. status, size, and resp_headers still reflect the attempted response. Fixes caddyserver#7938 Co-authored-by: Eugin Francis <13235453+euginfrancis@users.noreply.github.com> Signed-off-by: Faiyaz Rahman <faiyazrahman03@gmail.com>
faiyazrahmann
force-pushed
the
fix-7938-access-log-write-timeout
branch
from
September 4, 2026 07:43
6b741c0 to
882f6bc
Compare
WeidiDeng
approved these changes
Sep 4, 2026
Contributor
Author
|
@WeidiDeng fixed. kindly check if it works.
|
This was referenced Sep 30, 2026
jotikrishna
pushed a commit
to jotikrishna/caddy
that referenced
this pull request
Oct 7, 2026
Since caddyserver#7945, Server.ServeHTTP flushes the response in a deferred func when an HTTP/1.x request that is being access-logged took at least write_timeout. The deferred func already skips http.ErrHijacked, on the assumption that Flush reports a hijacked response that way. It does not. (*http.response).Hijack releases the bufio.Writer, and (*http.response).FlushError calls w.w.Flush() without checking for the hijack. Only Write and WriteHeader consult hijacked() and return ErrHijacked. So when the handler hijacked the connection, as reverse_proxy does when it passes through a 101 Switching Protocols upgrade, and the upgraded stream outlives write_timeout, the deferred flush reaches a nil bufio.Writer and panics with an invalid memory address. net/http recovers it and it fires only after the upgraded stream ended, so clients never notice, but every such connection ends with an error-level stack trace in the logs. responseRecorder already tracks the hijack for DetachAfterHijack and WriteResponse, so report it from FlushError too, which is what the deferred func expects. Fixes caddyserver#8151
jotikrishna
added a commit
to jotikrishna/caddy
that referenced
this pull request
Oct 7, 2026
Since caddyserver#7945, Server.ServeHTTP flushes the response in a deferred func when an HTTP/1.x request that is being access-logged took at least write_timeout. The deferred func already skips http.ErrHijacked, on the assumption that Flush reports a hijacked response that way. It does not. (*http.response).Hijack releases the bufio.Writer, and (*http.response).FlushError calls w.w.Flush() without checking for the hijack. Only Write and WriteHeader consult hijacked() and return ErrHijacked. So when the handler hijacked the connection, as reverse_proxy does when it passes through a 101 Switching Protocols upgrade, and the upgraded stream outlives write_timeout, the deferred flush reaches a nil bufio.Writer and panics with an invalid memory address. net/http recovers it and it fires only after the upgraded stream ended, so clients never notice, but every such connection ends with an error-level stack trace in the logs. responseRecorder already tracks the hijack for DetachAfterHijack and WriteResponse, so report it from FlushError too, which is what the deferred func expects. Fixes caddyserver#8151
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.
Fixes #7938
Adds a
write_errorfield to the access log with the real flush error on write timeouts, instead of silently logging status 200 for a response the client never got.status/size/resp_headersare left as the attempted response, per discussion in the issue.FlushError()on the recorder, swallowsErrHijackedReproduced locally (reverse_proxy to a slow backend + write 2s), curl still gets an empty reply, but the log now shows the actual i/o timeout error.
AI disclosure: AI was used during the initial investigation to help reproduce and trace the issue. The implementation, tests, and final changes were written and verified by myself.
