Fix broker reconnection: channel-based restart with persistent watchdog#84
Merged
shawnburke merged 5 commits intomainfrom Mar 9, 2026
Merged
Conversation
Overhaul broker restart logic to fix a ~30 minute reconnection gap
observed in "all" mode after registration deletes.
Root cause: when the broker died and the supervisor exhausted retries,
all background goroutines (auto-register, idle timeout) exited with
the done channel, leaving nothing to trigger recovery.
Changes:
1. Channel-based restart with generation dedup
All restart triggers (WS tunnel death, idle timeout, broker exit)
now send a restartRequest{reason, generation} to a single buffered
channel. A dedicated consumer goroutine deduplicates by generation:
stale requests from a previous broker lifecycle are discarded.
This replaces scattered direct Restart() calls with ad-hoc
cooldown timers.
2. Persistent watchdog with backoff
The restart consumer retries failed restarts with exponential
backoff (5s, 10s, 20s... capped at 5min). This ensures the broker
always recovers, even if re-registration temporarily fails.
3. Supervisor panic only on first start
The panic on max retries now only fires during initial startup
(fail-fast for misconfiguration). On subsequent restarts, the
error propagates to the watchdog for retry instead of crashing
the agent.
https://claude.ai/code/session_017w1aQgtC1Khfxo9oAQQYiS
24f949f to
93c0457
Compare
Tests the full reconnection path: force-kills the snyk-broker server container with SIGKILL (non-graceful disconnect), restarts it, and verifies the axon relay reconnects and can pass traffic again. https://claude.ai/code/session_017w1aQgtC1Khfxo9oAQQYiS
Instead of a separate goroutine for idle timeout detection, the restart consumer now ticks every minute and calls shouldRestart() to check if the broker has been idle too long. If so, it produces a restart request that flows through the same generation-check + retry logic. This eliminates one goroutine per broker instance and centralizes all restart decision-making in a single loop. https://claude.ai/code/session_017w1aQgtC1Khfxo9oAQQYiS
getRandomPort() was picking a random port in the 51000-52000 range,
which could collide between sequential tests if the OS hadn't released
the port yet. Use net.Listen(":0") to get a genuinely free port from
the OS instead.
https://claude.ai/code/session_017w1aQgtC1Khfxo9oAQQYiS
Reduces worst-case overshoot beyond the configured idle timeout from ~59s to ~14s. https://claude.ai/code/session_017w1aQgtC1Khfxo9oAQQYiS
Collaborator
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.