Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ownership in async_scope::detached_spawn #376

Merged
merged 1 commit into from
Nov 14, 2021

Conversation

ispeters
Copy link
Contributor

PR #372 has a subtle ownership bug that's mostly attributable to a lack
of tests for detached_spawn and friends. If async_scope::cleanup()
triggers set_done() on a detached promise because of the stop callback
registered 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 stop
callback 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.

PR #372 has a subtle ownership bug that's mostly attributable to a lack
of tests for `detached_spawn` and friends.  If `async_scope::cleanup()`
triggers `set_done()` on a detached promise because of the stop callback
registered on the scope's stope 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 stop
callback 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.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 14, 2021
@ispeters ispeters merged commit bfabd77 into broken-stdlib Nov 14, 2021
@ispeters ispeters deleted the fix_ownership_in_detached_spawn branch November 14, 2021 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants