Break poll loop out into subroutine guaranteed to quit before producer stop#941
Merged
Conversation
bgentry
approved these changes
Jun 4, 2025
bgentry
left a comment
Contributor
There was a problem hiding this comment.
💯, this definitely looks like the cause. Nice fix! 🎉
…r stop This one's aimed at fixing the race detector failure as observed in [1]. Honestly, I couldn't repro this locally even at 1,000 iteration, but reading the code, I'm pretty sure I know what the problem is. The `fetchAndRunLoop` would start a separate goroutine that'd use a timer to trigger a poll at `FetchPollInterval` so that fetches are occasionally performed even if listen/notify missed something. This inner goroutine would stop on context cancellation, but it wasn't guaranteed to return before a stop finished. Therefore, as the stress test called `Start` again, `fetchLimiter` could be modified while the goroutine was still accessing it from the last run of the producer. Fix this by making the fetch loop a "subroutine", which is a convention used already for other goroutines in `Start`. `Start` waits on all these goroutines to finish before completing a stop, therefore guaranteeing that the next iteration of `Start` can do so safely. [1] https://github.com/riverqueue/river/actions/runs/15419505042/job/43390545084
6cf8b8c to
38bd0b1
Compare
Contributor
Author
|
Thanks! And oops — a few typos in titles/description that are fixed now. |
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.
This one's aimed at fixing the race detector failure as observed in [1].
Honestly, I couldn't repro this locally even at 1,000 iteration, but
reading the code, I'm pretty sure I know what the problem is.
The
fetchAndRunLoopwould start a separate goroutine that'd use atimer to trigger a poll at
FetchPollIntervalso that fetches areoccasionally performed even if listen/notify missed something. This
inner goroutine would stop on context cancellation, but it wasn't
guaranteed to return before a stop finished. Therefore, as the stress
test called
Startagain,fetchLimitercould be modified while thegoroutine was still accessing it from the last run of the producer.
Fix this by making the fetch loop a "subroutine", which is a convention
used already for other goroutines in
Start.Startwaits on all thesegoroutines to finish before completing a stop, therefore guaranteeing
that the next iteration of
Startcan do so safely.[1] https://github.com/riverqueue/river/actions/runs/15419505042/job/43390545084