Skip to content

Stop broadcaster subscribe/unsubscribe from taking the stop signal - #313

Merged
jonyoder merged 1 commit into
mainfrom
fix-broadcaster-stop-race
Oct 1, 2026
Merged

jonyoder merged 1 commit into
mainfrom
fix-broadcaster-stop-race

Conversation

@jonyoder

@jonyoder jonyoder commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Subscribe, SubscribeOne and Unsubscribe all selected on stopSignal, so a call in flight when the single stop value was sent could take it. broadcast() then never stopped or closed stopSignal, and whoever sent the stop waited forever. Callers now wait on an internal done channel that broadcast() closes when it exits, so only broadcast() reads stopSignal.

This fixes the hang behind rstudio/package-manager#21066, and PPM can drop the wrapper added in rstudio/package-manager#21068.


Testing: New TestStopDuringSubscribe runs 50 goroutines calling Subscribe/SubscribeOne/Unsubscribe in a loop, sends a stop, and expects stopSignal to close within 1s. It fails on the first trial without the fix and passes -race -count=20 with it. just lint and just vet are clean.

Note: pkg/rsqueue/impls/database/queue.go (DatabaseQueue.SubscribeOne/Unsubscribe vs. its broadcast()) has the same pattern on stopChan. It isn't fixed here because WithDbTx copies don't carry stopChan, so it needs its own change.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonyoder

jonyoder commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Approved by @jonyoder in review of rstudio/package-manager#21068. Admin-merging on his behalf. Follow-up for the same race in DatabaseQueue: #314.

@jonyoder
jonyoder merged commit e14352c into main Oct 1, 2026
3 checks passed
@jonyoder
jonyoder deleted the fix-broadcaster-stop-race branch October 1, 2026 19:55
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.

1 participant