mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Don't leak a go routine on panic
This commit is contained in:
parent
a87c1b2d72
commit
a4ae7b9081
@ -28,6 +28,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||||
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||||
)
|
)
|
||||||
@ -119,6 +120,23 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
case <-after:
|
case <-after:
|
||||||
|
defer func() {
|
||||||
|
// resultCh needs to have a reader, since the function doing
|
||||||
|
// the work needs to send to it. This is defer'd to ensure it runs
|
||||||
|
// ever if the post timeout work itself panics.
|
||||||
|
go func() {
|
||||||
|
res := <-resultCh
|
||||||
|
if res != nil {
|
||||||
|
switch t := res.(type) {
|
||||||
|
case error:
|
||||||
|
utilruntime.HandleError(t)
|
||||||
|
default:
|
||||||
|
utilruntime.HandleError(fmt.Errorf("%v", res))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
|
||||||
postTimeoutFn()
|
postTimeoutFn()
|
||||||
tw.timeout(err)
|
tw.timeout(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user