Use send_closure for Td::close()/destroy() to ensure the correct call order.

This commit is contained in:
levlam 2021-10-25 06:47:20 +03:00
parent f7d073baa4
commit d9607b4a46

View File

@ -3094,9 +3094,10 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
return send_result(id, td_api::make_object<td_api::updates>(std::move(updates)));
}
case td_api::close::ID:
// need to send response synchronously before actual closing
send_result(id, td_api::make_object<td_api::ok>());
return close();
// need to send response before actual closing
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
send_closure(actor_id(this), &Td::close);
return;
default:
break;
}
@ -3132,8 +3133,9 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
}
case td_api::destroy::ID:
// need to send response synchronously before actual destroying
send_result(id, td_api::make_object<td_api::ok>());
return destroy();
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
send_closure(actor_id(this), &Td::destroy);
return;
default:
if (is_preinitialization_request(function_id)) {
break;
@ -4513,13 +4515,13 @@ void Td::on_request(uint64 id, const td_api::logOut &request) {
void Td::on_request(uint64 id, const td_api::close &request) {
// send response before actually closing
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
close();
send_closure(actor_id(this), &Td::close);
}
void Td::on_request(uint64 id, const td_api::destroy &request) {
// send response before actually destroying
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
destroy();
send_closure(actor_id(this), &Td::destroy);
}
void Td::on_request(uint64 id, td_api::checkAuthenticationBotToken &request) {