riverqueue / river

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

Preinitialize `workCancel` function in case `StopAndCancel` called before start #557

Closed brandur closed 2 months ago

brandur commented 2 months ago

This one's related to #549. Although the most proximate problem in that repro code is that there was no error check when calling Start, it did reveal a legitimate problem in that the River client will panic in case StopAndCancel is called before Start because workCancel was never set.

Here, initialize workCancel in the client's constructor. During normal operation this will be overwritten almost immediately on Start as the client starts up, but in case Start was never called or didn't run successfully, it provides a function for StopAndCancel to call so that it doesn't panic.

Fixes #549.

bgentry commented 2 months ago

@brandur oh, probably deserves a changelog entry too

brandur commented 2 months ago

@brandur oh, probably deserves a changelog entry too

Added.