From 2e30218223a7bf2b560fbaf79bac8d80ea4ece1c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 26 Apr 2016 15:43:04 -0700 Subject: 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 --- src/net/http/main_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/net/http/main_test.go') 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 +} -- cgit v1.3-5-g9baa