-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http/httputil: ReverseProxy doesn't handle connection/stream reset properly #34413
Comments
@toothrot I've update the issue to include HTTP/1 as well, and it seems neither HTTP/1 connection close nor HTTP/2 stream reset is handled by the reverse proxy --- a default 502 will be returned to the client. The risk would be the proxy doesn't close the connection to the client in HTTP/1, or doesn't send a |
You can change the ReverseProxy's default 502 behavior by setting your own ErrorHandler with whatever policy you'd like: https://golang.org/pkg/net/http/httputil/#ReverseProxy.ErrorHandler
Sorry, I don't follow. Could you reword? Or back up? I read your test code above (thanks for the nice bug report!) but I'm confused by this latest statement/question. |
Sorry for the confusion. I don't have enough tests to back it up yet. I meant that the connection error seen by the proxy is not properly returned to the client, which may confuse the client upon receiving a regular status code 502. E.g. client may choose its retry mechanism based on the response code/error. And I am assuming the |
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?
I am trying to test the behavior of HTTP forwarding using
httputil.Reverseproxy
. Especially the behavior when the backend server closes the connection (for HTTP/1) or resets the stream (for HTTP/2). To test the stream reset behavior, the server usespanic(http.ErrAbortHandler)
in the handler.Wrote some tests for these.
For HTTP1: https://github.com/jaricftw/go-http-reverseproxy/blob/master/http1_test.go#L20, which tests:
1). http1 client -> http1 server
2). http1 client -> httputil.Reverseproxy -> http1 server
For HTTP2: https://github.com/jaricftw/go-http-reverseproxy/blob/master/http2_test.go#L25, similarly:
1). h2c client -> h2c server
2). h2c client -> httputil.Reverseproxy (with h2c setup) -> h2c server
What did you expect to see?
I would expect all tests to pass. i.e. the response for W/ and W/O reverseproxy should be the same in the stream reset scenario
What did you see instead?
In the happy case, w/ and w/o reverseproxy tests all passed, for both HTTP/1 and HTTP/2.
However, I see different responses W/ and W/O reverseproxy for the connection/stream reset test cases:
For HTTP/1:
W/O reverseproxy:
W/ reverseproxy:
For HTTP/2:
W/O reverseproxy:
W/ reverseproxy:
The text was updated successfully, but these errors were encountered: