Repository navigation
Add Running to the broadcaster - #200
Merged
Merged
Conversation
A broadcaster which has stopped isn't watched until Run starts it, which in a goroutine can be after a watch. Start makes it watched again at once, and Run calls it, so a caller which watches it as soon as it has started it calls Start before it runs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the synchronous broadcaster startup change.
No open issues 🎉
What changed in this PR
Adds a synchronous Start() method so a stopped broadcaster can accept watches before Run begins in a goroutine, avoiding rejected watches during restart.
Changes:
- Introduces
Start()and delegates to it fromRun, preserving existing caller behavior. - Replaces restart polling with
Start()and adds coverage for accepting watches beforeRun.
| File | Description |
|---|---|
broadcaster/broadcaster.go |
Adds and documents Start(); calls it from Run. |
broadcaster/broadcaster_test.go |
Updates restart coverage and tests watch acceptance after Start(). |
Review effort: Balanced
Running reports whether the broadcaster is running, so it's watched, from when Run has started, until it stops, so a caller which runs it in a goroutine waits until it's running, before watching it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A broadcaster that has stopped refuses watches with
ErrServiceUnavailableuntilRunstarts it again. WhenRunis started in a goroutine, a watch made straight afterwards can come before it, and be refused. go-pg's pgbroadcaster hit this when a manager runs a second time: it reported that it was listening before its broadcaster was running.Running()is an atomic bool, as on the other managers. It's true from the momentRunclears the stopped state until it stops, so true means watches are accepted. A caller that startsRunin a goroutine waits forRunning()before reporting it's ready:Never run: a broadcaster that has never run accepts watches but isn't
Running().Runis otherwise unchanged.Tests: the restart in the
Stoppedtest waits forRunning(), and a newRunningtest checks the flag before, during and after a run. Clean under-racefive times.