]> Cypherpunks repositories - gostls13.git/commitdiff
http: close connection after printing panic stack trace
authorRoger Peppe <rogpeppe@gmail.com>
Tue, 13 Dec 2011 21:34:22 +0000 (16:34 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 13 Dec 2011 21:34:22 +0000 (16:34 -0500)
In a testing situation, it's possible for a local http
server to panic and the test exit without the stack trace
ever being printed.
Fixes #2480.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5414048

src/pkg/net/http/server.go

index fa9009517dbabe5659b737c906a031e35a090a30..56f56cb044dfd0802bcd2efc89a650aa4ede2fd2 100644 (file)
@@ -569,14 +569,14 @@ func (c *conn) serve() {
                if err == nil {
                        return
                }
-               if c.rwc != nil { // may be nil if connection hijacked
-                       c.rwc.Close()
-               }
-
                var buf bytes.Buffer
                fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err)
                buf.Write(debug.Stack())
                log.Print(buf.String())
+
+               if c.rwc != nil { // may be nil if connection hijacked
+                       c.rwc.Close()
+               }
        }()
 
        if tlsConn, ok := c.rwc.(*tls.Conn); ok {