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,14 +38,10 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor { ...@@ -38,14 +38,10 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
~AsyncioExecutor() override { ~AsyncioExecutor() override {
keepAliveRelease(); 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) { while (keepAliveCounter_ > 0) {
drive(); drive();
} }
} }
}
void add(Func func) override { void add(Func func) override {
queue_.putMessage(std::move(func)); queue_.putMessage(std::move(func));
...@@ -57,6 +53,11 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor { ...@@ -57,6 +53,11 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
void drive() noexcept override { void drive() noexcept override {
consumer_.consumeUntilDrained([](Func&& func) { 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 { try {
func(); func();
} catch (...) { } 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