MM-5639: Write panic to log on the way out (#16808)
* MM-5639: Write panic to log on the way out We introduce a panic pass-through layer which logs the panic at a critical level before crashing. This helps customers to easily get the panic output in their logging infrastructure, rather than having to go through journaltctl logs. https://mattermost.atlassian.net/browse/MM-5639 ```release-note Server crashes due to runtime panics are now captured as a log line. ``` * re-arrange panic order Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
01f264cd62
Коммит
57f2e7dcd4
@@ -4,10 +4,12 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"runtime/pprof"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -78,6 +80,21 @@ func runServer(configStore *config.Store, usedPlatform bool, interruptChan chan
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer server.Shutdown()
|
defer server.Shutdown()
|
||||||
|
// We add this after shutdown so that it can be called
|
||||||
|
// before server shutdown happens as it can close
|
||||||
|
// the advanced logger and prevent the mlog call from working properly.
|
||||||
|
defer func() {
|
||||||
|
// A panic pass-through layer which just logs it
|
||||||
|
// and sends it upwards.
|
||||||
|
if x := recover(); x != nil {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
pprof.Lookup("goroutine").WriteTo(&buf, 2)
|
||||||
|
mlog.Critical("A panic occurred",
|
||||||
|
mlog.Any("error", x),
|
||||||
|
mlog.String("stack", buf.String()))
|
||||||
|
panic(x)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if usedPlatform {
|
if usedPlatform {
|
||||||
mlog.Warn("The platform binary has been deprecated, please switch to using the mattermost binary.")
|
mlog.Warn("The platform binary has been deprecated, please switch to using the mattermost binary.")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user