diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-26 15:43:04 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-27 03:30:59 +0000 |
| commit | 2e30218223a7bf2b560fbaf79bac8d80ea4ece1c (patch) | |
| tree | d807ee391ca819da0dbf04b183fa350d4418f387 /src/net/http/main_test.go | |
| parent | 87bca88c703c1f14fe8473dc2f07dc521cf2b989 (diff) | |
| download | go-2e30218223a7bf2b560fbaf79bac8d80ea4ece1c.tar.xz | |
net/http: remove idle transport connections from Transport when server closes
Previously the Transport would cache idle connections from the
Transport for later reuse, but if a peer server disconnected
(e.g. idle timeout), we would not proactively remove the *persistConn
from the Transport's idle list, leading to a waste of memory
(potentially forever).
Instead, when the persistConn's readLoop terminates, remote it from
the idle list, if present.
This also adds the beginning of accounting for the total number of
idle connections, which will be needed for Transport.MaxIdleConns
later.
Updates #15461
Change-Id: Iab091f180f8dd1ee0d78f34b9705d68743b5557b
Reviewed-on: https://go-review.googlesource.com/22492
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/net/http/main_test.go')
| -rw-r--r-- | src/net/http/main_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/net/http/main_test.go b/src/net/http/main_test.go index 1163874ac2..d10fd89b54 100644 --- a/src/net/http/main_test.go +++ b/src/net/http/main_test.go @@ -120,3 +120,17 @@ func afterTest(t testing.TB) { } t.Errorf("Test appears to have leaked %s:\n%s", bad, stacks) } + +// waitCondition reports whether fn eventually returned true, +// checking immediately and then every checkEvery amount, +// until waitFor has elpased, at which point it returns false. +func waitCondition(waitFor, checkEvery time.Duration, fn func() bool) bool { + deadline := time.Now().Add(waitFor) + for time.Now().Before(deadline) { + if fn() { + return true + } + time.Sleep(checkEvery) + } + return false +} |
