Skip to content

Add Running to the broadcaster - #200

Merged
djthorpe merged 2 commits into
mainfrom
djt/1112/broadcaster-start
Nov 12, 2026
Merged

djthorpe merged 2 commits into
mainfrom
djt/1112/broadcaster-start

Conversation

@djthorpe

@djthorpe djthorpe commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

A broadcaster that has stopped refuses watches with ErrServiceUnavailable until Run starts it again. When Run is 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 moment Run clears the stopped state until it stops, so true means watches are accepted. A caller that starts Run in a goroutine waits for Running() before reporting it's ready:

    go b.Run(ctx)
    // wait until b.Running(), then b.Watch(...) is accepted
  • Never run: a broadcaster that has never run accepts watches but isn't Running().

  • Run is otherwise unchanged.

  • Tests: the restart in the Stopped test waits for Running(), and a new Running test checks the flag before, during and after a run. Clean under -race five times.

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>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 from Run, preserving existing caller behavior.
  • Replaces restart polling with Start() and adds coverage for accepting watches before Run.
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>
@djthorpe djthorpe changed the title Add Start to the broadcaster, so it's watched again before it runs Add Running to the broadcaster Nov 12, 2026
@djthorpe djthorpe self-assigned this Nov 12, 2026
@djthorpe
djthorpe merged commit 39d9fab into main Nov 12, 2026
2 checks passed
@djthorpe
djthorpe deleted the djt/1112/broadcaster-start branch November 12, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants