-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: connection leak with TLS and reading Body #24719
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
I can reproduce. It does not happen if the end of the body is not reached, which suggests the leak happens in the connection pooling logic. Connections are not reused and MaxIdleConnsPerHost is somehow ignored. Also happens without InsecureSkipVerify, ParseRequestURI, H/2 ( It does not happen with DefaultTransport, or calling CloseIdleConnections. |
Oh, didn't realize the
So if you create a new one every iteration it won't know about all the other ones and it will just hold onto the connection for future reuse (which never happens). You should make a single Client and reuse it for each iteration:
|
Thank you. That fixed the issue. |
- We were running out of file handlers similar to [this issue](golang/go#24719) [#164174371] Signed-off-by: Andrew Garner <[email protected]>
go version go1.10.1 darwin/amd64
darwin, amd64
Above program results in a large number (observed by checking
lsof -p <process_id>
) ofTCP connections in established state, eventually running out of file descriptors.
I see this issue only when I use TLS and do a ioutil.ReadAll.
Skipping either one of them results in a single established TCP connection.
The issue also goes away If I do
req.Close = true
afterreq, _ := http.NewRequest("GET", urlStr, nil)
The text was updated successfully, but these errors were encountered: