Merge pull request #75853 from roycaihw/fix/use-standard-stacktrace

apimachinery & apiserver: use stacktrace in the stdlib

Kubernetes-commit: f8d0b21b980f33e218b7e1f01a13bf3bd90713f9
This commit is contained in:
Kubernetes Publisher 2019-04-05 19:28:27 -07:00
commit 6b396918ed
5 changed files with 18 additions and 13 deletions

4
Godeps/Godeps.json generated
View File

@ -448,11 +448,11 @@
},
{
"ImportPath": "k8s.io/apimachinery",
"Rev": "ba051b3c4d9d"
"Rev": "8f13d758fb1a"
},
{
"ImportPath": "k8s.io/client-go",
"Rev": "a18eda0c053a"
"Rev": "89226ff90625"
},
{
"ImportPath": "k8s.io/component-base",

8
go.mod
View File

@ -65,8 +65,8 @@ require (
gopkg.in/yaml.v2 v2.2.1
gotest.tools v2.2.0+incompatible // indirect
k8s.io/api v0.0.0-20190405172450-8fc60343b75c
k8s.io/apimachinery v0.0.0-20190405172352-ba051b3c4d9d
k8s.io/client-go v0.0.0-20190405172624-a18eda0c053a
k8s.io/apimachinery v0.0.0-20190406052345-8f13d758fb1a
k8s.io/client-go v0.0.0-20190405212609-89226ff90625
k8s.io/component-base v0.0.0-20190405172946-88b5861287aa
k8s.io/klog v0.0.0-20190306015804-8e90cee79f82
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30
@ -329,8 +329,8 @@ replace (
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.1
gotest.tools => gotest.tools v2.2.0+incompatible
k8s.io/api => k8s.io/api v0.0.0-20190405172450-8fc60343b75c
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190405172352-ba051b3c4d9d
k8s.io/client-go => k8s.io/client-go v0.0.0-20190405172624-a18eda0c053a
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190406052345-8f13d758fb1a
k8s.io/client-go => k8s.io/client-go v0.0.0-20190405212609-89226ff90625
k8s.io/component-base => k8s.io/component-base v0.0.0-20190405172946-88b5861287aa
k8s.io/gengo => k8s.io/gengo v0.0.0-20190116091435-f8a0810f38af
k8s.io/heapster => k8s.io/heapster v1.2.0-beta.1

4
go.sum
View File

@ -196,8 +196,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
k8s.io/api v0.0.0-20190405172450-8fc60343b75c/go.mod h1:3Wzsx7slWzBw6GbPMeksreuwqpC7UoolhqORRc9g5XY=
k8s.io/apimachinery v0.0.0-20190405172352-ba051b3c4d9d/go.mod h1:ELqXqns4PTTzr6t0VpyJODef88bmhBzTAkXf2Sa8Nhc=
k8s.io/client-go v0.0.0-20190405172624-a18eda0c053a/go.mod h1:CwRy++LDGrMlpoULu2KnnlvejZMB49ldqV9WYq8foOE=
k8s.io/apimachinery v0.0.0-20190406052345-8f13d758fb1a/go.mod h1:ELqXqns4PTTzr6t0VpyJODef88bmhBzTAkXf2Sa8Nhc=
k8s.io/client-go v0.0.0-20190405212609-89226ff90625/go.mod h1:CwRy++LDGrMlpoULu2KnnlvejZMB49ldqV9WYq8foOE=
k8s.io/component-base v0.0.0-20190405172946-88b5861287aa/go.mod h1:rzoUhBvaiBqNzOTwpthQvq6ggcSIovKb2QQhfmNxE5k=
k8s.io/klog v0.0.0-20190306015804-8e90cee79f82 h1:SHucoAy7lRb+w5oC/hbXyZg+zX+Wftn6hD4tGzHCVqA=
k8s.io/klog v0.0.0-20190306015804-8e90cee79f82/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=

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

@ -92,23 +92,27 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
errCh := make(chan interface{})
// resultCh is used as both errCh and stopCh
resultCh := make(chan interface{})
tw := newTimeoutWriter(w)
go func() {
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)]
err = fmt.Sprintf("%v\n%s", err, buf)
}
errCh <- err
resultCh <- err
}()
t.handler.ServeHTTP(tw, r)
}()
select {
case err := <-errCh:
case err := <-resultCh:
// panic if error occurs; stop otherwise
if err != nil {
panic(err)
}