]> Cypherpunks repositories - gostls13.git/commit
net/http: make Transport.CloseIdleConnections also close pending dials
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 30 Sep 2014 01:16:15 +0000 (18:16 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 30 Sep 2014 01:16:15 +0000 (18:16 -0700)
commitf13cec9f5732dd09c51f90957c3d888aad782c27
tree3694ae41a0b8a23fe6af3feec1e5dc862399153a
parent912ec1990bd09f8fc128c3fa6b59105085aabc03
net/http: make Transport.CloseIdleConnections also close pending dials

See comment 4 of https://code.google.com/p/go/issues/detail?id=8483#c4:

"So if a user creates a http.Client, issues a bunch of
requests and then wants to shutdown it and all opened connections;
what is she intended to do? The report suggests that just waiting for
all pending requests and calling CloseIdleConnections won't do, as
there can be new racing connections. Obviously she can't do what
you've done in the test, as it uses the unexported function.  If this
happens periodically, it can lead to serious resource leaks (the
transport is also preserved alive).  Am I missing something?"

This CL tracks the user's intention to close all idle
connections (CloseIdleConnections sets it true; and making a
new request sets it false). If a pending dial finishes and
nobody wants it, before it's retained for a future caller, the
"wantIdle" bool is checked and it's closed if the user has
called CloseIdleConnections without a later call to make a new
request.

Fixes #8483

LGTM=adg
R=golang-codereviews, dvyukov, adg
CC=golang-codereviews, rsc
https://golang.org/cl/148970043
src/net/http/export_test.go
src/net/http/transport.go
src/net/http/transport_test.go