From 9936af80dd76a3400444a0fc6d18e8c3c4abcd8f Mon Sep 17 00:00:00 2001 From: OleksandrParshyn <43094723+OleksandrParshyn@users.noreply.github.com> Date: Sat, 1 Nov 2025 14:33:35 +0100 Subject: [PATCH] Fix: Invoke service.StopBot() in signal handlers (#3583) Ensures the global Telegram bot stop function (`service.StopBot()`) is called upon receiving system signals (SIGHUP for restart, SIGINT/SIGTERM for shutdown). This complements the changes in `tgbot.go` to guarantee a clean shutdown of the Telegram bot's Long Polling operation, fully resolving the 409 Conflict issue during panel restarts or shutdowns. Changes: - Added `service.StopBot()` call to the `syscall.SIGHUP` handler. - Added `service.StopBot()` call to the default shutdown handler. --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 94b23bc8..e2af2beb 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,10 @@ func runWebServer() { case syscall.SIGHUP: logger.Info("Received SIGHUP signal. Restarting servers...") + // --- FIX FOR TELEGRAM BOT CONFLICT (409): Stop bot before restart --- + service.StopBot() + // -- + err := server.Stop() if err != nil { logger.Debug("Error stopping web server:", err) @@ -106,6 +110,10 @@ func runWebServer() { log.Println("Sub server restarted successfully.") default: + // --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown --- + service.StopBot() + // ------------------------------------------------------------ + server.Stop() subServer.Stop() log.Println("Shutting down servers.")