Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: connection leak with TLS and reading Body #24719
go version go1.10.1 darwin/amd64
Above program results in a large number (observed by checking
I see this issue only when I use TLS and do a ioutil.ReadAll.
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: