fix(otelhttp,otelmux): retain flush and body-read errors in shared wrappers #10352
<!-- pull-request-dashboard-status -->
<!-- pull-request-dashboard-status-revision:24 -->
<!-- pull-request-dashboard-author-nudge-episode:42c3ebdd43994d5391d7e11df0bca675 -->
Pull request dashboard status
Waiting on the author · refreshed 2026-11-28 07:49 UTC
Respond to 7 review items (e.g. link a commit, explain why not, ask a follow-up):
<details>
<summary>Status above doesn't look right?</summary>
<br>
/dashboard route:reviewers to route it to them.</details>
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues block the changes to preserve flush and request-body read failures.
No open issues 🎉
<details>
<summary><strong>What changed in this PR</strong></summary>
Fixes #10344 by preserving flush and request-body read failures in the shared wrappers used by otelhttp and otelmux. Error classification and error.type reporting remain outside this PR’s scope.
Changes:
No review issues were identified. Tests were not independently run.
| File | Description |
| ---- | ----------- |
| internal/shared/request/resp_writer_wrapper.go.tmpl | Retains non-nil flush errors. |
| internal/shared/request/resp_writer_wrapper_test.go.tmpl | Tests retention after failed and successful flushes. |
| internal/shared/request/body_wrapper.go.tmpl | Preserves earlier read failures through EOF. |
| internal/shared/request/body_wrapper_test.go.tmpl | Tests read-error retention after EOF. |
| instrumentation/net/http/otelhttp/internal/request/resp_writer_wrapper.go | Regenerates flush-error retention for otelhttp. |
| instrumentation/net/http/otelhttp/internal/request/resp_writer_wrapper_test.go | Regenerates flush regression tests. |
| instrumentation/net/http/otelhttp/internal/request/body_wrapper.go | Regenerates body-read error retention for otelhttp. |
| instrumentation/net/http/otelhttp/internal/request/body_wrapper_test.go | Regenerates body-read regression tests. |
| instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper.go | Regenerates flush-error retention for otelmux. |
| instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper_test.go | Regenerates flush regression tests. |
| instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper.go | Regenerates body-read error retention for otelmux. |
| instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper_test.go | Regenerates body-read regression tests. |
</details>
<sub>Review effort: Balanced</sub>
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues remain for the shared HTTP wrapper error-retention fixes.
No open issues 🎉
<sub>Review effort: Balanced</sub>
errors.Is(err, io.EOF) suppresses wrapped EOF failures too, although io.ReadAll and otelmux's failure classification treat only literal io.EOF as clean completion. After plain EOF followed by fmt.Errorf("upload failed: %w", io.EOF), the caller receives a failure but Error() still reports plain EOF; a wrapped EOF also cannot replace an earlier non-EOF failure. Compare err != io.EOF, remove the unused errors import, add a regression for this sequence, and regenerate the body wrappers in both otelhttp and otelmux.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
The body wrapper suppresses wrapped EOF failures as clean completion, causing Error() to misreport failures returned to callers.
<details open>
<summary><strong>1 open issue</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 90.7%. Comparing base (
b4214b4) to head (feb256b).:warning: Report is 27 commits behind head on main.
<details><summary>Additional details and impacted files</summary>

@@ Coverage Diff @@
## main #10352 +/- ##
=======================================
Coverage 90.6% 90.7%
=======================================
Files 230 232 +2
Lines 16648 16804 +156
=======================================
+ Hits 15099 15253 +154
- Misses 1549 1551 +2
| Files with missing lines | Coverage Δ | |
|---|---|---|
| ...rilla/mux/otelmux/internal/request/body\_wrapper.go | 95.6% <100.0%> (+0.6%) | :arrow_up: |
| ...ux/otelmux/internal/request/resp\_writer\_wrapper.go | 100.0% <100.0%> (ø) | |
| ...net/http/otelhttp/internal/request/body\_wrapper.go | 95.6% <100.0%> (+0.6%) | :arrow_up: |
| ...p/otelhttp/internal/request/resp\_writer\_wrapper.go | 100.0% <100.0%> (ø) | |
... and 9 files with indirect coverage changes
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Fixed in 98bc2f07. updateReadData now treats only a literal io.EOF as clean completion: a wrapped EOF is stored as a failure and replaces an earlier clean EOF, while a clean EOF never erases an earlier real failure. Removed the errors import, added TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure, and regenerated the otelhttp and otelmux wrappers. go test ./internal/request/... passes in both modules.
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues remain for the changes that preserve I/O failures in the shared HTTP wrappers.
No open issues 🎉
<details>
<summary><strong>1 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
The retention condition is hard to follow. cleanEOF is used once, and w.err == nil || w.err == io.EOF overlaps with what the comment says. Early returns read more directly, and the three-line comment can shrink to one:
// A clean io.EOF must not overwrite an earlier recorded error.
if err == nil || (err == io.EOF && w.err != nil) {
return
}
w.err = err
This behaves the same: when err == io.EOF and w.err is nil or io.EOF, the old code stored io.EOF again, and the new code stores it through the final assignment. The same change applies to internal/shared/request/body_wrapper.go.tmpl and the otelmux copy.
The two wrappers disagree about which failure wins. FlushWithError and Write overwrite with the latest error, while the body wrapper keeps the earlier non-EOF error, and only a later non-EOF error replaces it. Please pick one policy and apply it to both, or add a comment on each explaining why they differ.
This also changes behavior for wrapped EOFs: fmt.Errorf("...: %w", io.EOF) is now recorded as a failure, not as clean completion. That's the right call, but the entry only mentions "non-EOF request body read errors". Please add a few words about wrapped EOFs so users who see a new error status know why.
There's no test for two different non-EOF errors in a row. Please add one asserting that the second replaces the first, so the "last non-EOF error wins" behavior is pinned down.
This covers a later successful flush not clearing the error. Please also assert that a later failing flush with a different error replaces the stored one, which pins the "keep the last non-nil error" comment in FlushWithError.
errorThenEOFReader and cleanEOFThenWrappedEOFReader are the same stub with different scripted results. Please replace them with one reader that returns a slice of errors in order, and turn the two tests (plus the one requested above) into a table-driven test. That cuts the boilerplate and makes the cases easy to extend.
Use require.ErrorIs(t, bw.Error(), io.EOF) here instead of comparing the error value with Equal.
Use assert.EqualError(t, bw.Error(), "upload failed: EOF") instead of comparing the .Error() string. Same for the generated test copies.
Addressed the errorlint findings in the regenerated wrappers: literal-EOF detection now uses an errors.Is helper that excludes wrapped errors, without treating a wrapped EOF as clean completion. Head is feb256b6; golangci-lint reports 0 issues and go test ./internal/request/... passes in both otelhttp and otelmux. The remaining check-links failure is an external 503 for the semantic-conventions migration URL in CHANGELOG.md, unrelated to this change.
@/tmp/opencode/replies/.txt
@/tmp/opencode/replies/.txt
@/tmp/opencode/replies/.txt
@/tmp/opencode/replies/.txt
@/tmp/opencode/replies/.txt
@/tmp/opencode/replies/ot_0955.txt
@/tmp/opencode/replies/ot_0962.txt
@/tmp/opencode/replies/ot_0968.txt
Your comments are broken.
helmipradita
Fixes #10344
Fix the two error-retention gaps in the shared request/response wrappers:
1.
RespWriterWrapper.FlushWithErrornow stores a non-nil flush error, soError()reports it. A later successful flush/write/copy does not clear the earlier failure (same retention rule already used byWrite/ReadFrom).2.
BodyWrapper.updateReadDatano longer letsio.EOFoverwrite an earlier non-EOF read failure. Plain EOF with no prior failure is still recorded, so ordinary completion stays clean for telemetry.Changes are made in
internal/shared/request/*.go.tmpland regenerated for bothotelhttpandotelmux.Tests:
TestRespWriterFlushWithErrorto assert retention and that a later successful flush keeps the error.TestBodyWrapperRetainsReadErrorAfterEOFcovering sentinel-then-EOF across repeated reads.go test ./...passes in bothinstrumentation/net/http/otelhttpandinstrumentation/github.com/gorilla/mux/otelmux.Error classification /
error.typewiring is intentionally left to #9754 and #9404, per the issue scope.