Commit 7e6bdbbd authored by Shai Szulanski's avatar Shai Szulanski Committed by Facebook GitHub Bot

Add warning when using TaskWithExecutor + InlineLikeExecutor

Summary: This is unsafe and leads to all kinds of bugs. It is unfortunately too late to ban it, but we can at least print a warning to help debugging and maybe discourage new uses.

Reviewed By: yfeldblum

Differential Revision: D29972469

fbshipit-source-id: 1534bcc69eaf8f105998d65c0a6503740924cffa
parent cda1e77c
......@@ -23,6 +23,7 @@
#include <folly/CancellationToken.h>
#include <folly/Executor.h>
#include <folly/GLog.h>
#include <folly/Portability.h>
#include <folly/ScopeGuard.h>
#include <folly/Traits.h>
......@@ -403,6 +404,16 @@ class FOLLY_NODISCARD TaskWithExecutor {
<< "QueuedImmediateExecutor is not safe and is not supported for coro::Task. "
<< "If you need to run a task inline in a unit-test, you should use "
<< "coro::blockingWait instead.";
if constexpr (kIsDebug) {
if (dynamic_cast<InlineLikeExecutor*>(promise.executor_.get())) {
FB_LOG_ONCE(ERROR)
<< "InlineLikeExecutor is not safe and is not supported for coro::Task. "
<< "If you need to run a task inline in a unit-test, you should use "
<< "coro::blockingWait or write your test using the CO_TEST* macros instead."
<< "If you are using folly::getCPUExecutor, switch to getGlobalCPUExecutor "
<< "or be sure to call setCPUExecutor first.";
}
}
auto& calleeFrame = promise.getAsyncFrame();
calleeFrame.setReturnAddress();
......
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