Commit bb7eca17 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: log handler panic before closing HTTP connection

Fix originally from rogpeppe in 5414048 but was rolled
back due to test breakage.

This CL makes the test more robust to order of operations.

Fixes #2480 again.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5536072
parent 01a0d39a
......@@ -904,17 +904,13 @@ func testHandlerPanic(t *testing.T, withHijack bool) {
panic("intentional death for testing")
}))
defer ts.Close()
_, err := Get(ts.URL)
if err == nil {
t.Logf("expected an error")
}
// Do a blocking read on the log output pipe so its logging
// doesn't bleed into the next test. But wait only 5 seconds
// for it.
done := make(chan bool)
done := make(chan bool, 1)
go func() {
buf := make([]byte, 1024)
buf := make([]byte, 4<<10)
_, err := pr.Read(buf)
pr.Close()
if err != nil {
......@@ -922,6 +918,12 @@ func testHandlerPanic(t *testing.T, withHijack bool) {
}
done <- true
}()
_, err := Get(ts.URL)
if err == nil {
t.Logf("expected an error")
}
select {
case <-done:
return
......
......@@ -569,14 +569,15 @@ 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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment