riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.22k stars 86 forks source link

fix StopAndTest after ongoing Stop #376

Closed bgentry closed 2 months ago

bgentry commented 2 months ago

@brandur while working on some stuff in the demo tonight, I realized that the hard stop was no longer working correctly if initiated after a soft Stop() was ongoing. I believe a regression or at least a change in behavior occurred with https://github.com/riverqueue/river/issues/272, because the shutdown logic in the demo app used to properly handle these shutdown scenarios.

Perhaps this isn't exactly a "bug", though it did used to work this way. In the past you didn't need to cancel the context for Stop() prior to calling StopAndCancel(), but now it appears that is required. This is because the start/stop service has a mutex which is held while Stop() is ongoing and so a subsequent concurrent call to StopAndCancel() cannot proceed until that first call has been "released" by cancelling its context.

I didn't have time to get any further on this tonight but figured you might have thoughts.