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-stopped → restart: 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
Problem
When the bot fails to authenticate (wrong password, user not found, IP blocked), it exits with code 1. But Docker's
restart: unless-stoppedignores the exit code and restarts indefinitely, causing:Fix
1.
cmd/bot/main.go— Exit code 0 on auth error2.
docker-compose.yml— Change restart policyrestart: unless-stopped→restart: on-failure3.
internal/rocket/client.go— Auth error handlingAlready done in PR #34:
isAuthError()wraps auth errors with prefix"authentication failed — check bot credentials:"Files Changed
cmd/bot/main.godocker-compose.ymlAcceptance Criteria
on-failure