Second try to fix producer test intermittency#921
Merged
Conversation
Last week I tried to fix an extraneous producer log on shutdown in #896. Unfortunately it still happens, and worse yet, it actually leads to test failures if the logging happens during an example test where it gets recorded (example [1]). --- FAIL: Example_encryptHook (0.39s) got: Secret message: This message is encrypted in the database, but plaintext in workers. producer: Producer status update, error updating in database want: Secret message: This message is encrypted in the database, but plaintext in workers. FAIL FAIL riverqueue.com/riverpro/riverencrypt 0.556s Looking over this code again, I think the problem was the addition of this cluster of lines: var subroutineWG sync.WaitGroup subroutineWG.Add(3) subroutineCtx, cancelSubroutines := context.WithCancelCause(context.WithoutCancel(fetchCtx)) go p.heartbeatLogLoop(subroutineCtx, &subroutineWG) go p.reportQueueStatusLoop(subroutineCtx, &subroutineWG) go p.reportProducerStatusLoop(subroutineCtx, &subroutineWG) Subroutines had been set up to not produce an error when they notice a start/stop's `startstop.ErrStop` stopping error, but with the new `subroutineCtx` and use of `WithoutCancel`, `ErrStop` will never make it down to those goroutines. They don't know not to log on a context cancellation, so errors are produced. Here, try to address the problem by making sure there's an `ErrStop` in the cancel error: cancelSubroutines(fmt.Errorf("producer stopped: %w", startstop.ErrStop)) The checks to know whether to log an error are using `errors.Is` and `context.Cause`, so this should work: if err != nil && errors.Is(context.Cause(ctx), startstop.ErrStop) { return } [1] https://github.com/riverqueue/riverpro/actions/runs/15047355176/job/42293190805
bgentry
approved these changes
May 23, 2025
bgentry
left a comment
Contributor
There was a problem hiding this comment.
Makes sense, hopefully that will take care of it!
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.
Last week I tried to fix an extraneous producer log on shutdown in #896.
Unfortunately it still happens, and worse yet, it actually leads to test
failures if the logging happens during an example test where it gets
recorded (example [1]).
Looking over this code again, I think the problem was the addition of
this cluster of lines:
Subroutines had been set up to not produce an error when they notice a
start/stop's
startstop.ErrStopstopping error, but with the newsubroutineCtxand use ofWithoutCancel,ErrStopwill never make itdown to those goroutines. They don't know not to log on a context
cancellation, so errors are produced.
Here, try to address the problem by making sure there's an
ErrStopinthe cancel error:
The checks to know whether to log an error are using
errors.Isandcontext.Cause, so this should work:[1] https://github.com/riverqueue/riverpro/actions/runs/15047355176/job/42293190805