diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2015-10-27 18:30:20 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-10-27 21:18:04 +0000 |
| commit | d3f88ce06c80a066cebf7239d6189424b1ae20cd (patch) | |
| tree | 1a6fa875ce5a48ecdb2029cd4281251f0c9d267f /src/net/http/httptest/server.go | |
| parent | e243d242d750f19cd1c3aefa7da1ad238f21502e (diff) | |
| download | go-d3f88ce06c80a066cebf7239d6189424b1ae20cd.tar.xz | |
net/http/httptest: close conns in StateNew on Server close
This part got dropped when we were debating between two solutions
in https://golang.org/cl/15151
Fixes #13032
Change-Id: I820b94f6c0c102ccf9342abf957328ea01f49a26
Reviewed-on: https://go-review.googlesource.com/16313
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/httptest/server.go')
| -rw-r--r-- | src/net/http/httptest/server.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/net/http/httptest/server.go b/src/net/http/httptest/server.go index b5f1149259..4a45b2b940 100644 --- a/src/net/http/httptest/server.go +++ b/src/net/http/httptest/server.go @@ -150,7 +150,25 @@ func (s *Server) Close() { s.Listener.Close() s.Config.SetKeepAlivesEnabled(false) for c, st := range s.conns { - if st == http.StateIdle { + // Force-close any idle connections (those between + // requests) and new connections (those which connected + // but never sent a request). StateNew connections are + // super rare and have only been seen (in + // previously-flaky tests) in the case of + // socket-late-binding races from the http Client + // dialing this server and then getting an idle + // connection before the dial completed. There is thus + // a connected connection in StateNew with no + // associated Request. We only close StateIdle and + // StateNew because they're not doing anything. It's + // possible StateNew is about to do something in a few + // milliseconds, but a previous CL to check again in a + // few milliseconds wasn't liked (early versions of + // https://golang.org/cl/15151) so now we just + // forcefully close StateNew. The docs for Server.Close say + // we wait for "oustanding requests", so we don't close things + // in StateActive. + if st == http.StateIdle || st == http.StateNew { s.closeConn(c) } } |
