Commit 40b40a1d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix retrying when the policy throws

Summary: [Folly] Fix `retrying` when the policy throws.

Differential Revision: D7392852

fbshipit-source-id: 3cb1d19697f111bf19047dc382056b39ad241035
parent f9326ade
......@@ -92,17 +92,19 @@ void retryingImpl(size_t k, Policy&& p, FF&& ff, Prom prom) {
return;
}
auto& x = t.exception();
auto q = pm(k, x);
auto q = makeFutureWith([&] { return pm(k, x); });
q.then([k,
prom = std::move(prom),
xm = std::move(x),
pm = std::move(pm),
ffm = std::move(ffm)](bool shouldRetry) mutable {
if (shouldRetry) {
ffm = std::move(ffm)](Try<bool> shouldRetry) mutable {
if (shouldRetry.hasValue() && shouldRetry.value()) {
retryingImpl(k, std::move(pm), std::move(ffm), std::move(prom));
} else {
} else if (shouldRetry.hasValue()) {
prom.setException(std::move(xm));
};
} else {
prom.setException(std::move(shouldRetry.exception()));
}
});
});
}
......
......@@ -96,6 +96,14 @@ TEST(RetryingTest, future_factory_throws) {
EXPECT_THROW(result.throwIfFailed(), ThrownException);
}
TEST(RetryingTest, policy_throws) {
struct eggs : exception {};
auto r = futures::retrying(
[](size_t, exception_wrapper) -> bool { throw eggs(); },
[](size_t) -> Future<size_t> { throw std::runtime_error("ha"); });
EXPECT_THROW(r.get(), eggs);
}
TEST(RetryingTest, policy_future) {
atomic<size_t> sleeps {0};
auto r = futures::retrying(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment