Skip to content

Docker restart loop on auth failure — exit code 0 and restart: on-failure #35

Description

@sunba91-su

Problem

When the bot fails to authenticate (wrong password, user not found, IP blocked), it exits with code 1. But Docker's restart: unless-stopped ignores the exit code and restarts indefinitely, causing:

  • IP-based rate limiting on Rocket.Chat
  • Account lockout
  • Resource waste

Fix

1. cmd/bot/main.go — Exit code 0 on auth error

if err := client.Connect(cfg.BotUser, cfg.BotPass); err != nil {
    log.Printf("Failed to connect: %v", err)
    if strings.Contains(err.Error(), "authentication failed") {
        log.Println("Auth failure is permanent — exiting to prevent restart loop")
        os.Exit(0)
    }
    os.Exit(1)
}

2. docker-compose.yml — Change restart policy

  • restart: unless-stoppedrestart: on-failure
  • Transient errors (exit != 0) → Docker restarts
  • Auth errors (exit = 0) → Docker stays stopped

3. internal/rocket/client.go — Auth error handling

Already done in PR #34: isAuthError() wraps auth errors with prefix "authentication failed — check bot credentials:"

Files Changed

  • cmd/bot/main.go
  • docker-compose.yml

Acceptance Criteria

  • Bot exits with code 0 on auth error
  • Docker restart policy is on-failure
  • Container stays stopped after auth failure (no restart loop)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions