Fix a race in Promise::setTry
authorAndrii Grynenko <andrii@fb.com>
Mon, 16 May 2016 21:06:54 +0000 (14:06 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Mon, 16 May 2016 21:08:46 +0000 (14:08 -0700)
commit87e5b4078f62e696ed901d64f0242ebc5fc5e62c
tree801fa7b9c96c94cbc570d470aa52c2f266e2b0c2
parent9b311838f4bf5fd9037949cc5910d8c66c26fcaa
Fix a race in Promise::setTry

Summary:
This fixes a race which can only be exposed if Promise is owned by the same thread which was calling await and Promise is fulfilled from a different thread. What could happen then was:
1. Thread 2 fulfills the promise and thus saves the value and posts Baton.
2. Thread 1 wakes up, await returns and then Thread 1 destroys the Promise.
3. Promise destructor checks value_, which is still not null, so it tries to fulfil it with exception.

Reviewed By: spalamarchuk

Differential Revision: D3306969

fbshipit-source-id: adf799cfd7b75b0201fa675a9e44ac7c7c42ac95
folly/experimental/fibers/Promise-inl.h