From a2ef43ca5ee384f0490fc148a0951a3285023fdf Mon Sep 17 00:00:00 2001 From: sunba91-su Date: Mon, 8 Jun 2026 19:58:21 +0330 Subject: [PATCH] fix: prevent Docker restart loop on auth failure Two changes to stop the bot from restarting indefinitely when credentials are wrong: 1. Exit with code 0 on authentication errors (Docker only restarts on non-zero exit when policy is on-failure) 2. Change docker-compose restart policy from unless-stopped to on-failure so transient errors (exit 1) restart but permanent auth failures (exit 0) stay stopped Closes #35 --- cmd/bot/main.go | 7 ++++++- docker-compose.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index b5dbff5..3425a9f 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -105,7 +105,12 @@ func main() { }) if err := client.Connect(cfg.BotUser, cfg.BotPass); err != nil { - log.Fatalf("Failed to connect: %v", err) + log.Printf("Failed to connect: %v", err) + if strings.Contains(err.Error(), "authentication failed") { + log.Println("Auth failure is permanent — exiting to prevent Docker restart loop") + os.Exit(0) + } + os.Exit(1) } defer client.Disconnect() diff --git a/docker-compose.yml b/docker-compose.yml index 3b36b7f..be2ed31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: https_proxy: "${https_proxy:-}" no_proxy: "${no_proxy:-}" container_name: geekbot - restart: unless-stopped + restart: on-failure env_file: .env volumes: - bot-data:/data