From e8176d63c6666d283d3b557fe8245b62c844a465 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Mon, 23 Aug 2021 19:16:14 +0100 Subject: [PATCH] Ensure that template compilation panics are sent to the logs Although panics within the rendering pipeline are caught and dealt with, panics that occur before that starts are unprotected and will kill Gitea without being sent to the logs. This PR adds a basic recovery handler to catch panics that occur after the logger is initialised and ensure that they're sent to the logger. Signed-off-by: Andrew Thornton --- cmd/web.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/web.go b/cmd/web.go index 6953e7c64f5d..963c81620747 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -86,6 +86,11 @@ func runWeb(ctx *cli.Context) error { _ = log.DelLogger("console") log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout)) } + defer func() { + if panicked := recover(); panicked != nil { + log.Fatal("PANIC: %v\n%s", panicked, string(log.Stack(2))) + } + }() managerCtx, cancel := context.WithCancel(context.Background()) graceful.InitManager(managerCtx)