-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/net/http2: Transport ignores net/http.Transport.Proxy once connected #25793
Comments
(CC: @bradfitz and @tombergan for x/net/http2.) |
tl;dr net/http executes Proxy whenever RoundTrip isn't delegated to alternate round tripper ( If you use See for more details: Slide A, Slide B, Video. Also I don’t think DisableKeepAlive has any effect on http2 which uses long lived connections. |
cc: @odeke-em |
This might be tricky to fix with the current interface between the two packages. It'll need some thinking. Worst case we could document it at least, but I'd rather fix it. |
This issue is still actual (go1.20.1). We're sending requests to same target server (e.g. https://api.myip.com/) using different proxies. This works correctly using HTTP/1.1, but with HTTP/2 all requests are sent using just one proxy (because net/http reuses already opened connection to target server and ignores differences in proxy configuration). Also, https://pkg.go.dev/net/http@go1.20.1#Transport says (in ForceAttemptHTTP2 description) HTTP/2 will be "conservatively disabled" if "a non-zero Dial, DialTLS, or DialContext func or TLSClientConfig is provided", but I provide both TLSClientConfig and DialContext while net/http still uses HTTP/2 (should I open a separate issue for this?). Possible workaround (to disable HTTP/2) is: client.Transport.TLSNextProto = make(map[string]func(authority string, c *tls.Conn) http.RoundTripper) |
BTW, is there any other ways to work around this without disabling HTTP/2? |
What version of Go are you using (
go version
)?go1.10.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
I've set up an HTTP2 client and server. The client does a few concurrent requests to the sever. The client's http.Transport has a Proxy function set which alters the requests's context. The http.Transport.DisableKeepAlives flag is also set to true.
Upon receiving the response, the contents of the context gets printed out.
My code in playground: https://play.golang.org/p/bx4GvEZ-suw
Can't be run in playground though, because of the HTTP/2 package and needed cert and key.
To get the cert + key run:
openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.pem -days 365 -nodes
in the directory of the file.What did you expect to see?
The context of every request altered, like so: (what happens if the http.Transport doesn't get configured for HTTP2)
What did you see instead?
Almost none of the requests passed through the http.Transport.Proxy function, even though the no keepalives flag has been set:
Not using HTTP2 on the client side seems to solve the issue completely. Playing with the 10ms processing time on the server and 10ms waiting time between starting goroutines either resolves the issue or make it worse. However this is not something you (should) have control over in a production environment.
This might be related to: #25620, however that one is on TCP level (where the http.Transport.Proxy is called, but not respected), while here the function isn't called at all.
The text was updated successfully, but these errors were encountered: