mirror of
https://github.com/golang/go
synced 2024-11-20 11:14:45 -07:00
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
This commit is contained in:
parent
01a0d39a7f
commit
bb7eca177a
@ -904,17 +904,13 @@ func testHandlerPanic(t *testing.T, withHijack bool) {
|
|||||||
panic("intentional death for testing")
|
panic("intentional death for testing")
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
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
|
// Do a blocking read on the log output pipe so its logging
|
||||||
// doesn't bleed into the next test. But wait only 5 seconds
|
// doesn't bleed into the next test. But wait only 5 seconds
|
||||||
// for it.
|
// for it.
|
||||||
done := make(chan bool)
|
done := make(chan bool, 1)
|
||||||
go func() {
|
go func() {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 4<<10)
|
||||||
_, err := pr.Read(buf)
|
_, err := pr.Read(buf)
|
||||||
pr.Close()
|
pr.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -922,6 +918,12 @@ func testHandlerPanic(t *testing.T, withHijack bool) {
|
|||||||
}
|
}
|
||||||
done <- true
|
done <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
_, err := Get(ts.URL)
|
||||||
|
if err == nil {
|
||||||
|
t.Logf("expected an error")
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
|
@ -569,14 +569,15 @@ func (c *conn) serve() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.rwc != nil { // may be nil if connection hijacked
|
|
||||||
c.rwc.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err)
|
fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err)
|
||||||
buf.Write(debug.Stack())
|
buf.Write(debug.Stack())
|
||||||
log.Print(buf.String())
|
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 {
|
if tlsConn, ok := c.rwc.(*tls.Conn); ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user