-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http/httptest: Server.Close should also client connections #4436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
To test this, we can make httptest's private newLocalListener function always first try to reuse the address of the most-recently-closed listener. In practice, this will make the net/http tests (which never run in parallel) always re-use the same address for all tests. This should cause tests to fail 100% of the time, as seen in failure above that motivated this issue. Then it'll be easy to verify the fix works, then we can undo the intentional address reuse before submitting. |
Yup, explicitly causing the port to be reused (as *BSD must do more often by default) causes the net/http tests to be unhappy: diff -r cda840e2befc src/pkg/net/http/httptest/server.go --- a/src/pkg/net/http/httptest/server.go Sun Nov 25 09:04:13 2012 -0800 +++ b/src/pkg/net/http/httptest/server.go Sun Nov 25 11:38:01 2012 -0800 @@ -50,6 +50,8 @@ return } +var lastAddr = make(chan string, 1) + func newLocalListener() net.Listener { if *serve != "" { l, err := net.Listen("tcp", *serve) @@ -58,6 +60,19 @@ } return l } + + // Try to reuse the most-recently-closed address first, just to make + // port-reuse bugs stand out easier. + select { + case addr := <-lastAddr: + l, err := net.Listen("tcp", addr) + if err == nil { + println("reused", addr) + return l + } + default: + } + l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { if l, err = net.Listen("tcp6", "[::1]:0"); err != nil { @@ -153,7 +168,13 @@ // Close shuts down the server and blocks until all outstanding // requests on this server have completed. func (s *Server) Close() { + addr := s.Listener.Addr().String() s.Listener.Close() + select { + case lastAddr <- addr: + default: + } s.wg.Wait() } |
This issue was closed by revision f97bb12. Status changed to Fixed. |
Issue #4021 has been merged into this issue. |
Issue #4021 has been merged into this issue. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: