Schedule close on the scheduler

Summary:
^

If Flipper stops, we cannot freely access the client outside of the scheduler.

There may be an scheduled operation that depends on it.

Instead, schedule the stop and wait until it finishes.

Reviewed By: cekkaewnumchai

Differential Revision: D37814820

fbshipit-source-id: 44217b5f623a8d92211a3d72a4a204d674b4bb76
This commit is contained in:
Lorenzo Blasa
2022-07-13 05:09:34 -07:00
committed by Facebook GitHub Bot
parent e7591b2a81
commit 039b647666

View File

@@ -305,10 +305,18 @@ void FlipperConnectionManagerImpl::stop() {
} }
isStarted_ = false; isStarted_ = false;
if (client_) { std::shared_ptr<std::promise<void>> joinPromise =
client_->disconnect(); std::make_shared<std::promise<void>>();
} std::future<void> join = joinPromise->get_future();
client_ = nullptr; flipperScheduler_->schedule([this, joinPromise]() {
if (client_) {
client_->disconnect();
}
client_ = nullptr;
joinPromise->set_value();
});
join.wait();
} }
bool FlipperConnectionManagerImpl::isOpen() const { bool FlipperConnectionManagerImpl::isOpen() const {
@@ -453,6 +461,9 @@ void FlipperConnectionManagerImpl::requestSignedCertificate() {
certificateExchangeCompleted_ = false; certificateExchangeCompleted_ = false;
flipperScheduler_->schedule([this, message, gettingCert]() { flipperScheduler_->schedule([this, message, gettingCert]() {
if (!client_) {
return;
}
client_->sendExpectResponse( client_->sendExpectResponse(
folly::toJson(message), folly::toJson(message),
[this, gettingCert](const std::string& response, bool isError) { [this, gettingCert](const std::string& response, bool isError) {