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

Fix AsyncioExecutor shutdown

Summary: It's unsafe to destroy the object before keepAlive reaches 0. We can still skip running the scheduled functions if those are unsafe to run.

Reviewed By: nanshu

Differential Revision: D19605152

fbshipit-source-id: b99c28dc65da2a5621ce5260491c13754fca03ad
parent 36d628a1
......@@ -38,12 +38,8 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
~AsyncioExecutor() override {
keepAliveRelease();
if (!FOLLY_DETAIL_PY_ISFINALIZING()) {
// if Python is finalizing calling drive() WILL segfault.
// any code that could have been called is now inconsequential.
while (keepAliveCounter_ > 0) {
drive();
}
while (keepAliveCounter_ > 0) {
drive();
}
}
......@@ -57,6 +53,11 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
void drive() noexcept override {
consumer_.consumeUntilDrained([](Func&& func) {
if (FOLLY_DETAIL_PY_ISFINALIZING()) {
// if Python is finalizing calling scheduled functions MAY segfault.
// any code that could have been called is now inconsequential.
return;
}
try {
func();
} catch (...) {
......
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