Fix ownership in async_scope::detached_spawn #376
Merged
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.
PR #372 has a subtle ownership bug that's mostly attributable to a lack
of tests for
detached_spawn
and friends. Ifasync_scope::cleanup()
triggers
set_done()
on a detached promise because of the stop callbackregistered on the scope's stop source, we'll delete the operation state
while using its
inplace_stop_source
, leading to a use-after-free.This diff fixes the problem by making the guilty stop callback a
part-owner in the operation state. There are now three owners: the
future<>
(if there is one), the operation itself, and the stopcallback that propagates stop requests from the scope's stop source to
each operation's stop source.
I'll figure out how to write a unit test that captures the now-fixed
failure mode in a future PR.