remove TrimSuffix and document buffer size

This commit is contained in:
Haowei Cai 2019-04-01 11:02:39 -07:00
parent 5c81571b01
commit 0e61b77826
2 changed files with 5 additions and 2 deletions

View File

@ -25,7 +25,6 @@ import (
"net/http"
"net/url"
goruntime "runtime"
"strings"
"time"
"k8s.io/apimachinery/pkg/api/errors"
@ -197,10 +196,12 @@ func finishRequest(timeout time.Duration, fn resultFunc) (result runtime.Object,
defer func() {
panicReason := recover()
if panicReason != nil {
// Same as stdlib http server code. Manually allocate stack
// trace buffer size to prevent excessively large logs
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:goruntime.Stack(buf, false)]
panicReason = strings.TrimSuffix(fmt.Sprintf("%v\n%s", panicReason, string(buf)), "\n")
panicReason = fmt.Sprintf("%v\n%s", panicReason, buf)
// Propagate to parent goroutine
panicCh <- panicReason
}

View File

@ -99,6 +99,8 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
err := recover()
if err != nil {
// Same as stdlib http server code. Manually allocate stack
// trace buffer size to prevent excessively large logs
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]