fix dead-lock in Future when executor discards function
authorSven Over <over@fb.com>
Wed, 29 Mar 2017 10:48:52 +0000 (03:48 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 29 Mar 2017 10:52:21 +0000 (03:52 -0700)
commit08a2ff010687bfd73e331a6fc09c0151cd98bdc8
treeda4465363713bd78a36ccecd1d8abee362cfe63c
parent2a60bc196ca0ec395b029ad1e066873fb0676bdb
fix dead-lock in Future when executor discards function

Summary:
This diff adds two tests to futures/test/ViaTest.cpp:
viaDummyExecutorFutureSetValueFirst and
viaDummyExecutorFutureSetCallbackFirst. The latter resulted in a
dead-lock before the fix contained in this diff.

It is important that the callback function is destroyed after
it is executed, since it may capture objects (like a Promise)
that should be destroyed (so that e.g. a corresponding Future
throws BrokenPromise). When the callback is executed via an
executor, it is possible that the executor doesn't get around to
executing the task. We shouldn't rely on the task being executed
to do necessary clean-up. That clean-up should (also) happen
when the task (with its captured data) is destroyed (in the
spirit of RIAA).

Reviewed By: djwatson

Differential Revision: D4779215

fbshipit-source-id: d029cf8b8f7b55e1b03357749c5fb62d95986ca7
folly/futures/detail/Core.h
folly/futures/test/ViaTest.cpp