aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/export_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-04-30 21:11:42 -0500
committerBrad Fitzpatrick <bradfitz@golang.org>2016-05-01 05:47:09 +0000
commitabc1472d78c70888473634497b49b1c2e1bb6569 (patch)
treeb1c9de2b49dc7c966748b48ad578c0ba99d428ba /src/net/http/export_test.go
parent0ab78df9ea602d6bc9cf45dbd610c3d6f534cb58 (diff)
downloadgo-abc1472d78c70888473634497b49b1c2e1bb6569.tar.xz
net/http: add Transport.IdleConnTimeout
Don't keep idle HTTP client connections open forever. Add a new knob, Transport.IdleConnTimeout, and make the default be 90 seconds. I figure 90 seconds is more than a minute, and less than infinite, and I figure enough code has things waking up once a minute polling APIs. This also removes the Transport's idleCount field which was unused and redundant with the size of the idleLRU map (which was actually used). Change-Id: Ibb698a9a9a26f28e00a20fe7ed23f4afb20c2322 Reviewed-on: https://go-review.googlesource.com/22670 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/export_test.go')
-rw-r--r--src/net/http/export_test.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go
index d1baed896a..3ebc51b19e 100644
--- a/src/net/http/export_test.go
+++ b/src/net/http/export_test.go
@@ -81,9 +81,6 @@ func (t *Transport) IdleConnKeysForTesting() (keys []string) {
keys = make([]string, 0)
t.idleMu.Lock()
defer t.idleMu.Unlock()
- if t.idleConn == nil {
- return
- }
for key := range t.idleConn {
keys = append(keys, key.String())
}
@@ -91,12 +88,22 @@ func (t *Transport) IdleConnKeysForTesting() (keys []string) {
return
}
-func (t *Transport) IdleConnCountForTesting(cacheKey string) int {
+func (t *Transport) IdleConnStrsForTesting() []string {
+ var ret []string
t.idleMu.Lock()
defer t.idleMu.Unlock()
- if t.idleConn == nil {
- return 0
+ for _, conns := range t.idleConn {
+ for _, pc := range conns {
+ ret = append(ret, pc.conn.LocalAddr().String()+"/"+pc.conn.RemoteAddr().String())
+ }
}
+ sort.Strings(ret)
+ return ret
+}
+
+func (t *Transport) IdleConnCountForTesting(cacheKey string) int {
+ t.idleMu.Lock()
+ defer t.idleMu.Unlock()
for k, conns := range t.idleConn {
if k.String() == cacheKey {
return len(conns)