Commit 6f2f3a1a authored by Chris Keeline's avatar Chris Keeline Committed by Facebook Github Bot

Allow calls to runInMainContext during exception handling

Summary:
This should be ok to do. Main thing I'm not sure about is if it's ok
to change these DCHECKs to CHECKs. We could probably also pass state into
InlineFunctionRunner::run() to keep these as DCHECKS here and CHECK in our
implementation.

Reviewed By: andriigrynenko

Differential Revision: D15463243

fbshipit-source-id: c1de7198e8bf48d8af0e03361bed493642e6c173
parent 9cb3d6a3
...@@ -174,7 +174,8 @@ void Fiber::preempt(State state) { ...@@ -174,7 +174,8 @@ void Fiber::preempt(State state) {
DCHECK_EQ(fiberManager_.activeFiber_, this); DCHECK_EQ(fiberManager_.activeFiber_, this);
DCHECK_EQ(state_, RUNNING); DCHECK_EQ(state_, RUNNING);
DCHECK_NE(state, RUNNING); DCHECK_NE(state, RUNNING);
DCHECK(!std::current_exception()); CHECK(state == AWAITING_IMMEDIATE || !std::current_exception());
CHECK(state == AWAITING_IMMEDIATE || !std::uncaught_exception());
state_ = state; state_ = state;
......
...@@ -2431,3 +2431,32 @@ TEST(FiberManager, addTaskEagerNested) { ...@@ -2431,3 +2431,32 @@ TEST(FiberManager, addTaskEagerNested) {
EXPECT_TRUE(eagerTaskDone); EXPECT_TRUE(eagerTaskDone);
EXPECT_TRUE(secondTaskDone); EXPECT_TRUE(secondTaskDone);
} }
TEST(FiberManager, swapWithException) {
folly::EventBase evb;
auto& fm = getFiberManager(evb);
bool done = false;
fm.addTask([&] {
try {
throw std::logic_error("test");
} catch (const std::exception& e) {
// Ok to call runInMainContext in exception unwinding
runInMainContext([&] { done = true; });
}
});
evb.loop();
EXPECT_TRUE(done);
fm.addTask([&] {
try {
throw std::logic_error("test");
} catch (const std::exception& e) {
Baton b;
// Can't block during exception unwinding
ASSERT_DEATH(b.try_wait_for(std::chrono::milliseconds(1)), "");
}
});
evb.loop();
}
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