aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net/http/serve_test.go7
-rw-r--r--src/net/http/server.go2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go
index 08b9862e16..6fd9912b5e 100644
--- a/src/net/http/serve_test.go
+++ b/src/net/http/serve_test.go
@@ -4988,3 +4988,10 @@ func testServerShutdown(t *testing.T, h2 bool) {
t.Fatal("second request should fail. server should be shut down")
}
}
+
+// Issue 17878: tests that we can call Close twice.
+func TestServerCloseDeadlock(t *testing.T) {
+ var s Server
+ s.Close()
+ s.Close()
+}
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 0959ac6f85..d78fd71a8d 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -2362,7 +2362,7 @@ func (s *Server) closeDoneChanLocked() {
// regardless of their state. For a graceful shutdown, use Shutdown.
func (s *Server) Close() error {
s.mu.Lock()
- defer s.mu.Lock()
+ defer s.mu.Unlock()
s.closeDoneChanLocked()
err := s.closeListenersLocked()
for c := range s.activeConn {