@@ -212,4 +212,3 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)
|
|||||||
httpWriter.WriteHeader(http.StatusInternalServerError)
|
httpWriter.WriteHeader(http.StatusInternalServerError)
|
||||||
httpWriter.Write([]byte("recover from panic situation"))
|
httpWriter.Write([]byte("recover from panic situation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
goflag "flag"
|
goflag "flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@@ -34,6 +35,7 @@ import (
|
|||||||
"kubesphere.io/kubesphere/pkg/utils/jwtutil"
|
"kubesphere.io/kubesphere/pkg/utils/jwtutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
goRuntime "runtime"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
container := runtime.Container
|
container := runtime.Container
|
||||||
container.Filter(filter.Logging)
|
container.Filter(filter.Logging)
|
||||||
container.DoNotRecover(false)
|
container.DoNotRecover(false)
|
||||||
|
container.RecoverHandler(logStackOnRecover)
|
||||||
|
|
||||||
for _, webservice := range container.RegisteredWebServices() {
|
for _, webservice := range container.RegisteredWebServices() {
|
||||||
for _, route := range webservice.Routes() {
|
for _, route := range webservice.Routes() {
|
||||||
@@ -133,3 +136,18 @@ func initializeAdminJenkins() {
|
|||||||
func initializeDevOpsDatabase() {
|
func initializeDevOpsDatabase() {
|
||||||
devops_mysql.OpenDatabase()
|
devops_mysql.OpenDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user