mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge pull request #161 from fnproject/catch-panics
catch request panics in goroutine
This commit is contained in:
@@ -109,7 +109,7 @@ func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, logDB
|
|||||||
|
|
||||||
setMachineId()
|
setMachineId()
|
||||||
setTracer()
|
setTracer()
|
||||||
s.Router.Use(loggerWrap, traceWrap)
|
s.Router.Use(loggerWrap, traceWrap, panicWrap)
|
||||||
s.bindHandlers(ctx)
|
s.bindHandlers(ctx)
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -203,6 +203,20 @@ func whoAmI() net.IP {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func panicWrap(c *gin.Context) {
|
||||||
|
defer func(c *gin.Context) {
|
||||||
|
if rec := recover(); rec != nil {
|
||||||
|
err, ok := rec.(error)
|
||||||
|
if !ok {
|
||||||
|
err = fmt.Errorf("fn: %v", rec)
|
||||||
|
}
|
||||||
|
handleErrorResponse(c, err)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
|
}(c)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
func loggerWrap(c *gin.Context) {
|
func loggerWrap(c *gin.Context) {
|
||||||
ctx, _ := common.LoggerWithFields(c.Request.Context(), extractFields(c))
|
ctx, _ := common.LoggerWithFields(c.Request.Context(), extractFields(c))
|
||||||
|
|
||||||
@@ -297,16 +311,12 @@ func (s *Server) startGears(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const runHeader = `
|
const runHeader = `
|
||||||
____ __
|
______
|
||||||
/ __ \_________ ______/ /__
|
/ ____/___
|
||||||
/ / / / ___/ __ / ___/ / _ \
|
/ /_ / __ \
|
||||||
/ /_/ / / / /_/ / /__/ / __/
|
/ __/ / / / /
|
||||||
\_________ \__,_/\___/_/\____
|
/_/ /_/ /_/
|
||||||
/ ____/_ __ ___ _____/ /_( )___ ____ _____
|
`
|
||||||
/ /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
|
|
||||||
/ __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
|
|
||||||
/_/ \____/_/ /_/\___/\__/_/\____/_/ /_/____/
|
|
||||||
`
|
|
||||||
fmt.Println(runHeader)
|
fmt.Println(runHeader)
|
||||||
logrus.Infof("Serving Functions API on address `%s`", listen)
|
logrus.Infof("Serving Functions API on address `%s`", listen)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user