diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index d95ec30ef..139fa3558 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -283,7 +283,7 @@ Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::dest } Status SessionConnection::on_destroy_auth_key(const mtproto_api::DestroyAuthKeyRes &destroy_auth_key) { - CHECK(need_destroy_auth_key_); + LOG_CHECK(need_destroy_auth_key_) << static_cast(mode_); LOG(INFO) << to_string(destroy_auth_key); return callback_->on_destroy_auth_key(); } diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index d7e0cca7e..9e461b1d4 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -972,6 +972,9 @@ void Session::connection_open_finish(ConnectionInfo *info, auto name = PSTRING() << get_name() << "::Connect::" << mode_name << "::" << raw_connection->debug_str_; LOG(INFO) << "Finished to open connection " << name; info->connection = make_unique(mode, std::move(raw_connection), &auth_data_); + if (can_destroy_auth_key()) { + info->connection->destroy_key(); + } info->connection->set_online(connection_online_flag_, is_main_); info->connection->set_name(name); Scheduler::subscribe(info->connection->get_poll_info().extract_pollable_fd(this)); @@ -1206,11 +1209,6 @@ void Session::loop() { need_flush = true; } } - if (can_destroy_auth_key()) { - if (main_connection_.connection) { - main_connection_.connection->destroy_key(); - } - } if (need_flush) { connection_flush(&main_connection_); need_flush = false;