Skip to content

Commit

Permalink
Ensure that RequestActor function isn't run while closing.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Nov 8, 2021
1 parent 244986a commit 544ec92
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions td/telegram/RequestActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class RequestActor : public Actor {
}

void loop() override {
if (G()->close_flag()) {
return do_send_error(Global::request_aborted_error());
}

PromiseActor<T> promise_actor;
FutureActor<T> future;
init_promise_future(&promise_actor, &future);
Expand Down Expand Up @@ -65,9 +69,9 @@ class RequestActor : public Actor {
auto error = future_.move_as_error();
if (error == Status::Error<FutureActor<T>::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 {
Expand Down

0 comments on commit 544ec92

Please sign in to comment.