futures: fix behaviour when executors don't exec callback
authorSven Over <over@fb.com>
Fri, 29 Jul 2016 11:45:35 +0000 (04:45 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Fri, 29 Jul 2016 11:53:24 +0000 (04:53 -0700)
commit9095cd537c3dc1acc1ee9577ae704308d780e2e4
tree19822a726cbb82102ce60991b598e1c9bf53cb59
parent0cc6ea398f7296d6cb31282b838dccf613b2040d
futures: fix behaviour when executors don't exec callback

Summary:
When future callbacks are to be executed by an executor (via `via`)
and the executor does not actually execute the callback function
(for whatever reason), then waiting for the final future (the one
returned by `via`) block forever. In case the callback function
that got passed to the executor gets destroyed without being executed,
the future should be set to a folly::BrokenPromise exception instead
of remaining unset forever.

This diff modifies the reference counting in folly::detail::Core
to make sure the reference held by the callback function is
properly removed not only after the callback gets executed, but
also when the callback is destroyed without having been executed.

Reviewed By: yfeldblum

Differential Revision: D3455931

fbshipit-source-id: debb6f3563384a658d1e0149a4aadbbcb268938c
folly/futures/detail/Core.h
folly/futures/test/ExecutorTest.cpp
folly/futures/test/SelfDestructTest.cpp