diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 203ce5bd7..2d00807d4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4036,7 +4036,7 @@ void Td::request(uint64 id, tl_object_ptr function) { break; } if (is_preauthentication_request(function_id)) { - // pending_preauthentication_requests_.emplace_back(id, std::move(function)); + pending_preauthentication_requests_.emplace_back(id, std::move(function)); // return; } return send_error_raw(id, 401, "Initialization parameters are needed"); @@ -4069,7 +4069,7 @@ void Td::request(uint64 id, tl_object_ptr function) { break; } if (is_preauthentication_request(function_id)) { - // pending_preauthentication_requests_.emplace_back(id, std::move(function)); + pending_preauthentication_requests_.emplace_back(id, std::move(function)); // return; } return send_error_raw(id, 401, "Database encryption key is needed"); @@ -4409,6 +4409,23 @@ void Td::clear_handlers() { result_handlers_.clear(); } +void Td::clear_requests() { + while (!pending_alarms_.empty()) { + auto it = pending_alarms_.begin(); + auto alarm_id = it->first; + pending_alarms_.erase(it); + alarm_timeout_.cancel_timeout(alarm_id); + } + while (!request_set_.empty()) { + uint64 id = *request_set_.begin(); + if (destroy_flag_) { + send_error_impl(id, make_error(401, "Unauthorized")); + } else { + send_error_impl(id, make_error(500, "Internal Server Error: closing")); + } + } +} + void Td::clear() { if (close_flag_ >= 2) { return; @@ -4433,20 +4450,7 @@ void Td::clear() { LOG(DEBUG) << "NetQueryDispatcher was stopped " << timer; state_manager_.reset(); LOG(DEBUG) << "StateManager was cleared " << timer; - while (!pending_alarms_.empty()) { - auto it = pending_alarms_.begin(); - auto alarm_id = it->first; - pending_alarms_.erase(it); - alarm_timeout_.cancel_timeout(alarm_id); - } - while (!request_set_.empty()) { - uint64 id = *request_set_.begin(); - if (destroy_flag_) { - send_error_impl(id, make_error(401, "Unauthorized")); - } else { - send_error_impl(id, make_error(500, "Internal Server Error: closing")); - } - } + clear_requests(); if (is_online_) { is_online_ = false; alarm_timeout_.cancel_timeout(ONLINE_ALARM_ID); @@ -4520,9 +4524,11 @@ void Td::close_impl(bool destroy_flag) { return; } if (state_ == State::WaitParameters) { + clear_requests(); return on_closed(); } if (state_ == State::Decrypt) { + clear_requests(); if (destroy_flag) { TdDb::destroy(parameters_); } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 27dc60124..82faf610d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -262,6 +262,8 @@ class Td final : public NetQueryCallback { void clear_handlers(); // void destroy_handler(ResultHandler *handler); + void clear_requests(); + static bool is_internal_config_option(Slice name); void on_config_option_updated(const string &name);