mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
http2: conditionally log stacks from panics in Server Handlers like net/http
Updates golang/go#17790 Change-Id: I7bc596d9a80490d545ad3d1de5859efce34714f6 Reviewed-on: https://go-review.googlesource.com/33102 TryBot-Result: Gobot Gobot <gobot@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
@@ -35,3 +35,7 @@ func configureServer18(h1 *http.Server, h2 *Server) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func shouldLogPanic(panicValue interface{}) bool {
|
||||
return panicValue != nil && panicValue != http.ErrAbortHandler
|
||||
}
|
||||
|
||||
@@ -12,3 +12,7 @@ func configureServer18(h1 *http.Server, h2 *Server) error {
|
||||
// No IdleTimeout to sync prior to Go 1.8.
|
||||
return nil
|
||||
}
|
||||
|
||||
func shouldLogPanic(panicValue interface{}) bool {
|
||||
return panicValue != nil
|
||||
}
|
||||
|
||||
@@ -1856,15 +1856,17 @@ func (sc *serverConn) runHandler(rw *responseWriter, req *http.Request, handler
|
||||
rw.rws.stream.cancelCtx()
|
||||
if didPanic {
|
||||
e := recover()
|
||||
// Same as net/http:
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
sc.writeFrameFromHandler(FrameWriteRequest{
|
||||
write: handlerPanicRST{rw.rws.stream.id},
|
||||
stream: rw.rws.stream,
|
||||
})
|
||||
sc.logf("http2: panic serving %v: %v\n%s", sc.conn.RemoteAddr(), e, buf)
|
||||
// Same as net/http:
|
||||
if shouldLogPanic(e) {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
sc.logf("http2: panic serving %v: %v\n%s", sc.conn.RemoteAddr(), e, buf)
|
||||
}
|
||||
return
|
||||
}
|
||||
rw.handlerDone()
|
||||
|
||||
Reference in New Issue
Block a user