Commit 0ad95397 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix a race in FutureAwaitable

Summary: Make sure the future object doesn't get destroyed concurrently with the setCallback_ call.

Reviewed By: yfeldblum

Differential Revision: D15122238

fbshipit-source-id: c8de1cd158f317c3ed7591460ca2cccfa7633ae7
parent 9fac201a
...@@ -2004,7 +2004,11 @@ class FutureAwaitable { ...@@ -2004,7 +2004,11 @@ class FutureAwaitable {
} }
void await_suspend(std::experimental::coroutine_handle<> h) { void await_suspend(std::experimental::coroutine_handle<> h) {
future_.setCallback_([this, h](Try<T>&& result) mutable { // FutureAwaitable may get destroyed as soon as the callback is executed.
// Make sure the future object doesn't get destroyed until setCallback_
// returns.
auto future = std::move(future_);
future.setCallback_([this, h](Try<T>&& result) mutable {
result_ = std::move(result); result_ = std::move(result);
h.resume(); h.resume();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment