remove TrimSuffix and document buffer size

Kubernetes-commit: 0e61b77826f23cbf835002a9eef5722bb1cfdf53
This commit is contained in:
Haowei Cai 2019-04-01 11:02:39 -07:00 committed by Kubernetes Publisher
parent 278cabecf3
commit 4ff581692b
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"
@ -195,10 +194,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)]