提交 8edcd0c3 编写于 作者: R runzexia 提交者: zryfish

wrap panic

Signed-off-by: Nrunzexia <runzexia@yunify.com>
上级 6dd86221
......@@ -18,6 +18,7 @@
package app
import (
"bytes"
goflag "flag"
"fmt"
"github.com/golang/glog"
......@@ -37,6 +38,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops_mysql"
"log"
"net/http"
goRuntime "runtime"
)
var jsonIter = jsoniter.ConfigCompatibleWithStandardLibrary
......@@ -74,7 +76,7 @@ func Run(s *options.ServerRunOptions) error {
container := runtime.Container
container.DoNotRecover(false)
container.Filter(filter.Logging)
container.RecoverHandler(logStackOnRecover)
for _, webservice := range container.RegisteredWebServices() {
for _, route := range webservice.Routes() {
log.Println(route.Method, route.Path)
......@@ -195,3 +197,19 @@ func waitForResourceSync() {
log.Println("resources sync success")
}
func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("recover from panic situation: - %v\r\n", panicReason))
for i := 2; ; i += 1 {
_, file, line, ok := goRuntime.Caller(i)
if !ok {
break
}
buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line))
}
glog.Error(buffer.String())
httpWriter.WriteHeader(http.StatusInternalServerError)
httpWriter.Write([]byte("recover from panic situation"))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册