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>
diff --git a/http2/go18.go b/http2/go18.go
index e000203..8c0dd25 100644
--- a/http2/go18.go
+++ b/http2/go18.go
@@ -35,3 +35,7 @@
}
return nil
}
+
+func shouldLogPanic(panicValue interface{}) bool {
+ return panicValue != nil && panicValue != http.ErrAbortHandler
+}
diff --git a/http2/not_go18.go b/http2/not_go18.go
index c1fa591..2e600dc 100644
--- a/http2/not_go18.go
+++ b/http2/not_go18.go
@@ -12,3 +12,7 @@
// No IdleTimeout to sync prior to Go 1.8.
return nil
}
+
+func shouldLogPanic(panicValue interface{}) bool {
+ return panicValue != nil
+}
diff --git a/http2/server.go b/http2/server.go
index ca77d71..ea260da 100644
--- a/http2/server.go
+++ b/http2/server.go
@@ -1856,15 +1856,17 @@
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()