From 544ec92aa9066b67e8cf0125bdaa95dda7edd366 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 8 Nov 2021 19:17:36 +0300 Subject: [PATCH] Ensure that RequestActor function isn't run while closing. --- td/telegram/RequestActor.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/td/telegram/RequestActor.h b/td/telegram/RequestActor.h index ef3f36e3d215..6dedd0db47b1 100644 --- a/td/telegram/RequestActor.h +++ b/td/telegram/RequestActor.h @@ -30,6 +30,10 @@ class RequestActor : public Actor { } void loop() override { + if (G()->close_flag()) { + return do_send_error(Global::request_aborted_error()); + } + PromiseActor promise_actor; FutureActor future; init_promise_future(&promise_actor, &future); @@ -65,9 +69,9 @@ class RequestActor : public Actor { auto error = future_.move_as_error(); if (error == Status::Error::HANGUP_ERROR_CODE>()) { // dropping query due to lost authorization or lost promise - // Td may be already closed, so we should check is auth_manager_ is empty - bool is_authorized = td_->auth_manager_ && td_->auth_manager_->is_authorized(); - if (is_authorized) { + if (G()->close_flag()) { + do_send_error(Global::request_aborted_error()); + } else if (!td_->auth_manager_->is_authorized()) { LOG(ERROR) << "Promise was lost"; do_send_error(Status::Error(500, "Query can't be answered due to a bug in TDLib")); } else {