fix(rfc9457): do not mutate a shared ProblemError - #3094
Merged
Conversation
aldas
requested changes
Sep 11, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3094 +/- ##
==========================================
+ Coverage 93.34% 95.73% +2.38%
==========================================
Files 43 44 +1
Lines 4735 4034 -701
==========================================
- Hits 4420 3862 -558
+ Misses 192 172 -20
+ Partials 123 0 -123 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
ProblemDetailsHTTPErrorHandlerfills in the zero-valuedType,TitleandStatusfields by writing them back into the*ProblemErrorit was handed:pecomes fromerrors.As, so it points at whatever value the application returned. Returning a package level sentinel is the idiomatic way to express a reusable error, and the same pointer then reaches the handler on every request that returns it:Two things go wrong. Concurrent requests write to the same struct, which the race detector reports:
And the write is permanent. After the first request the sentinel is no longer the value the application declared;
Typehas become"about:blank"andTitlehas become"Not Found". An application that later inspects or re-serializes its own error sees fields it never set.The
ProblemErrorerpath has the same shape wheneverProblemError()returns a shared pointer.The change
The defaults are applied to a copy, so the response is unchanged and the caller's value is left alone. Nothing else about the handler moves.
Testing
TestProblemDetailsHTTPErrorHandler_DoesNotMutateSharedProblemserves one request that returns a sentinel, checks the response still carries the fully defaulted body, and then compares the sentinel with a copy taken before the request.Against the current code it fails on the mutation:
With this change
go test -race ./...is clean across all three packages.