You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some more context here: I'm using httputil.ReverseProxy and I want to record a metric once per request which tracks the result of the request. ReverseProxy.ErrorHandler seems like a reasonable place to add such a metric for the case when the request fails. However, it's not clear from the docs if ErrorHandler could be called more than once for a single request.
Looking at the code, it turns out that ErrorHandler will be called multiple times in some cases. One such case is here https://go.dev/play/p/P_8ZOOmh4UV
On the other hand, ReverseProxy.defaultErrorHandler should not be called more than once per request. It calls http.ResponseWriter.WriteHeader which requires "at most one 2xx-5xx header".
Ideally the ReverseProxy interface would be clarified so that it is simple to track how many requests failed.
seankhliao
changed the title
net/http/httputil.ReverseProxy calls WriteHeader multiple times on a single response
net/http/httputil: ReverseProxy calls WriteHeader multiple times on a single response
Nov 13, 2024
Change https://go.dev/cl/627635 mentions this issue: net/http/httputil: return after handling error
dmitshur
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Nov 18, 2024
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/P_8ZOOmh4UV
What did you expect to see?
response.WriteHeader
should be called exactly once with 502 as the status code.What did you see instead?
ReverseProxy calls
response.WriteHeader
multiple times on one response.The text was updated successfully, but these errors were encountered: