Fix one more race in Promise::setTry
authorAndrii Grynenko <andrii@fb.com>
Wed, 18 May 2016 00:21:56 +0000 (17:21 -0700)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Wed, 18 May 2016 00:23:25 +0000 (17:23 -0700)
Summary:
Baton::post has to be the last step of Promise::setTry. If Promise is not owned by
the posting thread, it may be destroyed right after Baton::post is called.

Reviewed By: pavlo-fb

Differential Revision: D3312506

fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189

folly/experimental/fibers/Promise-inl.h

index 108a2ac45325cf92690895bcc142b543f58b2fb1..67459855a2f70eccdbf10edbb3543232963a7336 100644 (file)
@@ -63,9 +63,9 @@ void Promise<T>::setTry(folly::Try<T>&& t) {
   *value_ = std::move(t);
   value_ = nullptr;
 
+  // Baton::post has to be the last step here, since if Promise is not owned by
+  // the posting thread, it may be destroyed right after Baton::post is called.
   baton_->post();
-
-  baton_ = nullptr;
 }
 
 template <class T>