Assume exception when Executor::add throws
authorHans Fugal <fugalh@fb.com>
Tue, 21 Apr 2015 18:19:04 +0000 (11:19 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:47:54 +0000 (16:47 -0700)
commitdf50885c695dc72d0897291c2deecd6c91f0395b
tree49e80b15e8be601e6fb2aa20b7c9b3078439d614
parentad932c32057925606acb5156dd58e2626a8cccc3
Assume exception when Executor::add throws

Summary:
Rather than crashing spectacularly, if `Executor::add` throws (e.g. because the queue is full), then discard the result we got and assume the exception the executor threw instead.

Alternatively, we could pass this exceptional Try to the callback (without an executor, as it is here), but not perturb `result_`. This would mean two different world views in these two code snippets:

auto f1 = makeFuture(42).via(&crappyExecutor);
f1.value(); // 42 (no callback happened)
f1.then(...); // would see the executor's exception. Would also be ill-advised to do this after value()

auto f2 = makeFuture(42).via(&crappyExecutor)
.then([](int x) { return x * 2; }); // skipped
f2.value(); // throws executor's exception

It feels rude to throw away the result, but it feels too potentially dangerous to allow this split view of the world.

Test Plan: modified unit

Reviewed By: jsedgwick@fb.com

Subscribers: exa, folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2007729

Tasks: 5306911

Signature: t1:2007729:1429627114:b627ce758ce9231298f1b28e203ccc1ee415ed9a
folly/futures/detail/Core.h
folly/futures/test/ExecutorTest.cpp