From 235dc44f414bc5666033d47a7277676c27f55b69 Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Sat, 24 Apr 2021 13:17:11 -0400 Subject: [PATCH] recover from panic on shutdown --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 813c5c9..5173200 100644 --- a/main.go +++ b/main.go @@ -197,9 +197,16 @@ func main() { Bridge.Mode = bridgeModeConstant Bridge.DiscordChannelID = Bridge.BridgeConfig.CID go func() { + defer func() { + if r := recover(); r != nil { + fmt.Println("Bridge paniced", r) + } + }() for { Bridge.startBridge() - log.Println("Bridge died. Restarting") + log.Println("Bridge died") + time.Sleep(5 * time.Second) + log.Println("Restarting") } }() default: @@ -211,7 +218,7 @@ func main() { // Shutdown on OS signal sc := make(chan os.Signal, 1) - signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) + signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) <-sc log.Println("OS Signal. Bot shutting down")