]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/httptest: protect against port reuse
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 25 Nov 2012 23:23:20 +0000 (15:23 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 25 Nov 2012 23:23:20 +0000 (15:23 -0800)
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

index 0ad05483a4cca75b06ee948081158d9ad8cad7a4..fc52c9a2efce7b0d7f46399969b92ddf603d0a56 100644 (file)
@@ -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