Fix closing Td before initialization.

GitOrigin-RevId: fcdb17b70d2dc0ac2f18dfe98aa3bb535ce50829
This commit is contained in:
levlam 2018-02-09 13:29:50 +03:00
parent 7c4ecdf650
commit 4614933a1e
3 changed files with 21 additions and 10 deletions

View File

@ -3689,7 +3689,7 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
return send_result(id, td_api::make_object<td_api::authorizationStateWaitTdlibParameters>());
case td_api::setTdlibParameters::ID:
return answer_ok_query(
id, set_td_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_)));
id, set_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_)));
default:
return send_error_raw(id, 401, "Initialization parameters are needed");
}
@ -3990,18 +3990,22 @@ void Td::dec_actor_refcnt() {
// NetQueryDispatcher will be closed automatically
close_flag_ = 4;
} else if (close_flag_ == 4) {
LOG(WARNING) << "ON_CLOSED";
close_flag_ = 5;
send_update(td_api::make_object<td_api::updateAuthorizationState>(
td_api::make_object<td_api::authorizationStateClosed>()));
callback_->on_closed();
dec_stop_cnt();
on_closed();
} else {
UNREACHABLE();
}
}
}
void Td::on_closed() {
LOG(WARNING) << "ON_CLOSED";
close_flag_ = 5;
send_update(td_api::make_object<td_api::updateAuthorizationState>(
td_api::make_object<td_api::authorizationStateClosed>()));
callback_->on_closed();
dec_stop_cnt();
}
void Td::dec_stop_cnt() {
stop_cnt_--;
if (stop_cnt_ == 0) {
@ -4129,6 +4133,9 @@ void Td::close_impl(bool destroy_flag) {
if (close_flag_) {
return;
}
if (state_ == State::WaitParameters) {
return on_closed();
}
if (state_ == State::Decrypt) {
if (destroy_flag) {
TdDb::destroy(parameters_);
@ -4520,7 +4527,7 @@ Status Td::fix_parameters(TdParameters &parameters) {
return Status::OK();
}
Status Td::set_td_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) {
Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) {
if (!clean_input_string(parameters->api_hash_) && !clean_input_string(parameters->system_language_code_) &&
!clean_input_string(parameters->device_model_) && !clean_input_string(parameters->system_version_) &&
!clean_input_string(parameters->application_version_)) {

View File

@ -206,6 +206,8 @@ class Td final : public NetQueryCallback {
void inc_request_actor_refcnt();
void dec_request_actor_refcnt();
void on_closed();
void dec_stop_cnt();
TdParameters parameters_;
@ -783,7 +785,7 @@ class Td final : public NetQueryCallback {
void clear();
void close_impl(bool destroy_flag);
Status fix_parameters(TdParameters &parameters) TD_WARN_UNUSED_RESULT;
Status set_td_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
Status set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters) TD_WARN_UNUSED_RESULT;
// Actor
void start_up() override;

View File

@ -635,7 +635,9 @@ class CliClient final : public Actor {
close_flag_ = false;
ready_to_stop_ = false;
td_ = create_actor<ClientActor>("Td-proxy", make_td_callback());
td_ = create_actor<ClientActor>("ClientActor1", make_td_callback());
td_ = create_actor<ClientActor>("ClientActor2", make_td_callback());
ready_to_stop_ = false;
auto bad_parameters = td_api::make_object<td_api::tdlibParameters>();
bad_parameters->database_directory_ = "/..";