Commit 0895c3af authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix Executor::KeepAlive use in thenError

Summary: onError destroys the Core, which holds a Executor::KeepAlive, so we have to capture it before calling onError.

Differential Revision: D13250857

fbshipit-source-id: 5f458765f0b8ccb225502c26413ff7bfdd46fe15
parent a9a8d1d0
...@@ -1093,12 +1093,13 @@ Future<T> Future<T>::thenError(F&& func) && { ...@@ -1093,12 +1093,13 @@ Future<T> Future<T>::thenError(F&& func) && {
// Forward to onError but ensure that returned future carries the executor // Forward to onError but ensure that returned future carries the executor
// Allow for applying to future with null executor while this is still // Allow for applying to future with null executor while this is still
// possible. // possible.
auto* e = this->getExecutor(); auto* ePtr = this->getExecutor();
auto e = folly::getKeepAliveToken(ePtr ? *ePtr : InlineExecutor::instance());
return std::move(*this) return std::move(*this)
.onError([func = std::forward<F>(func)](ExceptionType& ex) mutable { .onError([func = std::forward<F>(func)](ExceptionType& ex) mutable {
return std::forward<F>(func)(ex); return std::forward<F>(func)(ex);
}) })
.via(e ? e : &InlineExecutor::instance()); .via(std::move(e));
} }
template <class T> template <class T>
...@@ -1107,13 +1108,14 @@ Future<T> Future<T>::thenError(F&& func) && { ...@@ -1107,13 +1108,14 @@ Future<T> Future<T>::thenError(F&& func) && {
// Forward to onError but ensure that returned future carries the executor // Forward to onError but ensure that returned future carries the executor
// Allow for applying to future with null executor while this is still // Allow for applying to future with null executor while this is still
// possible. // possible.
auto* e = this->getExecutor(); auto* ePtr = this->getExecutor();
auto e = folly::getKeepAliveToken(ePtr ? *ePtr : InlineExecutor::instance());
return std::move(*this) return std::move(*this)
.onError([func = std::forward<F>(func)]( .onError([func = std::forward<F>(func)](
folly::exception_wrapper&& ex) mutable { folly::exception_wrapper&& ex) mutable {
return std::forward<F>(func)(std::move(ex)); return std::forward<F>(func)(std::move(ex));
}) })
.via(e ? e : &InlineExecutor::instance()); .via(std::move(e));
} }
template <class T> template <class T>
......
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