From f97bb12bb02b1a5dd0e36032c8079e019fef9d54 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 25 Nov 2012 15:23:20 -0800 Subject: [PATCH] net/http/httptest: protect against port reuse Should make BSDs more reliable. (they seem to reuse ports quicker than Linux) Tested by hand with local modifications to force reuse on Linux. (net/http tests failed before, pass now) Details in the issue. Fixes #4436 R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/6847101 --- src/pkg/net/http/httptest/server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pkg/net/http/httptest/server.go b/src/pkg/net/http/httptest/server.go index 0ad05483a4..fc52c9a2ef 100644 --- a/src/pkg/net/http/httptest/server.go +++ b/src/pkg/net/http/httptest/server.go @@ -155,6 +155,10 @@ func NewTLSServer(handler http.Handler) *Server { func (s *Server) Close() { s.Listener.Close() s.wg.Wait() + s.CloseClientConnections() + if t, ok := http.DefaultTransport.(*http.Transport); ok { + t.CloseIdleConnections() + } } // CloseClientConnections closes any currently open HTTP connections -- 2.48.1