-
Notifications
You must be signed in to change notification settings - Fork 18k
x/net/http2: Transport leaks goroutines (newClientConn) #25759
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
Comments
Happens on 1.9 too. Can you post a self-contained reproducer without the dependency on leaktest ? /cc @bradfitz |
As in, write a leaktest myself? |
You can even copy the relevant code if that makes it easier. But yes, a self-contained repro without any external dependency is preferred. We can even turn this into a main function without a test setup. |
This should do it https://gist.github.com/jadekler/ce72bbc03abafdf67930c5d018dae4df |
From the doc:
In this case it's a connection that is being used for h2 messages. TCP connections used for h2 are long lived. When http requests/responses are going back and forth, there needs to be some concurrent code ( @jadekler it looks like you have some h2 experience. Maybe you can help me understand what the proper behavior should be/why my logic is incorrect. |
Thanks, @jadekler for reporting this issue and @meirf thanks for clarifying the problem. The need for some concurrent code is clear here. Just it is kind of not fair nor clean to keep them running around if user explicitly wants to close his I guess this is big change, but we cannot close background go routines implicitly. |
I don't see the bug here. As @meirf said, this is working as intended. The "leaked" goroutines are intentionally running because they're the cached connection to make future HTTP requests to the same host faster. This happens for both HTTP/1 and HTTP/2. Use https://golang.org/pkg/net/http/#Transport.CloseIdleConnections to close idle connections if you want to shut them down. |
@bradfitz That makes sense, but it's not clear to me how to get at using that method. In github.com/GoogleCloudPlatform/google-cloud-go our clients have many-layered transports; Is there some better way than the following to get at that method?
If that is the way to get to it; what if one transport in the stack (such as |
The cloud & oauth2 libraries all support passing down a client/transport if that matters. (see https://godoc.org/golang.org/x/oauth2#HTTPClient) Then you can just retain your old Transport (to call close on it) and not use the default (unexported) one in their code. |
Thanks! defering BTW is there any mention about this behavior (leaving some go routines for a while) in the some |
There is: https://golang.org/pkg/net/http/#Transport
|
perfect, thanks. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?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?
Using
github.com/fortytw2/leaktest
go test -v -run TestJean
What did you expect to see?
PASS
What did you see instead?
The text was updated successfully, but these errors were encountered: