mirror of
https://github.com/golang/go
synced 2024-11-21 16:34:42 -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")
|
||||
}))
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user