Commit bc4e31a8 authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Facebook GitHub Bot

Fix bug with calling addTaskEager from another FiberManager

Summary:
The current code is calling `runInMainContext` on the FiberManager that we're scheduling to, which will do nothing if we're calling it from another fiber manager. This will assume fiber stack as a main stack which is incorrect.

This diff fixes it to call `folly::fibers::runInMainContext` that would properly call `runInMainContext` on the active FiberManager.

Reviewed By: andriigrynenko

Differential Revision: D25116215

fbshipit-source-id: 1d13f436a0599c077e7531dc1fe75f3a143e3478
parent 194b7732
......@@ -307,7 +307,7 @@ inline void FiberManager::runEagerFiber(Fiber* fiber) {
}
inline void FiberManager::runEagerFiberImpl(Fiber* fiber) {
runInMainContext([&] {
folly::fibers::runInMainContext([&] {
auto prevCurrentFiber = std::exchange(currentFiber_, fiber);
SCOPE_EXIT { currentFiber_ = prevCurrentFiber; };
runFibersHelper([&] { runReadyFiber(fiber); });
......
......@@ -2619,6 +2619,27 @@ TEST(FiberManager, addTaskEagerNested) {
EXPECT_TRUE(secondTaskDone);
}
TEST(FiberManager, addTaskEagerNestedFiberManager) {
folly::EventBase evb;
auto& fm = getFiberManager(evb);
FiberManager::Options opts;
opts.stackSize *= 2;
auto& fm2 = getFiberManager(evb, FiberManager::FrozenOptions(opts));
bool eagerTaskDone{false};
fm.addTask([&] {
fm2.addTaskEager([&] {
EXPECT_FALSE(fm.hasActiveFiber());
eagerTaskDone = true;
});
});
evb.loop();
EXPECT_TRUE(eagerTaskDone);
}
TEST(FiberManager, swapWithException) {
folly::EventBase evb;
auto& fm = getFiberManager(evb);
......
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