]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix Server.Close double Lock
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 10 Nov 2016 16:43:15 +0000 (16:43 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 10 Nov 2016 18:30:49 +0000 (18:30 +0000)
Fixes #17878

Change-Id: I062ac514239068c58175c9ee7964b3590f956a82
Reviewed-on: https://go-review.googlesource.com/33026
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/http/serve_test.go
src/net/http/server.go

index 08b9862e163a4417981832052ef9be7feff00e60..6fd9912b5e0259745d73a3b576336b69f3bd4677 100644 (file)
@@ -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()
+}
index 0959ac6f854e49f47cd57148f0f7b778800eaa2d..d78fd71a8dfc358e13fdbd6d4c3b2bad7c1fa713 100644 (file)
@@ -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 {