Make sure the ticker thread can die gracefully #422
Closed
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.
Fixes #416. See also previous discussion in #417 and #421.
Thanks for working on this test! I reworked the test to avoid adding overhead outside running tests and reuse the once_cell dev-dependency (which has a nicer API anyway) instead of adding lazy_static.
I also weakened the guarantee from your test: instead of asserting that the ticker terminates, I think it's strong enough to assert that the ticker is sleeping. At that point, it always only has access to a
Weak
, so if all strong references to the underlying data have been dropped, the ticker will fail to upgrade and terminate cleanly. I implemented this by changing yourAtomicBool
to indicate whether the ticker is running, setting tofalse
when the ticker goes to sleep andtrue
when it wakes up again.This allows us to fix this issue by simply moving the
Drop
impl fromBarState
toProgressBarInner
, having it lock theMutex
during drop. This means that:Drop
impl will wait for the ticker to go to sleep.Drop
code is running, it will need to wait untilDrop
drops the lock.Drop
is run, it will find thatstate.state.is_finished()
and terminate cleanly.ProgressBarInner
have dropped, it will terminate cleanly.I think that covers everything?