diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index e72c5e592..87793ef46 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -21,6 +21,7 @@ #include "td/telegram/net/NetQueryDispatcher.h" #include "td/telegram/NotificationManager.h" #include "td/telegram/PasswordManager.h" +#include "td/telegram/StateManager.h" #include "td/telegram/StickersManager.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" @@ -837,7 +838,7 @@ void AuthManager::update_state(State new_state, bool force, bool should_save_sta if (should_save_state) { save_state(); } - if (new_state == State::LoggingOut || new_state == State::DestroyingKeys || new_state == State::Closing) { + if (new_state == State::LoggingOut || new_state == State::DestroyingKeys) { send_closure(G()->state_manager(), &StateManager::on_logging_out, true); } send_closure(G()->td(), &Td::send_update, diff --git a/td/telegram/StateManager.cpp b/td/telegram/StateManager.cpp index 94c399ebc..a46e97326 100644 --- a/td/telegram/StateManager.cpp +++ b/td/telegram/StateManager.cpp @@ -85,7 +85,7 @@ void StateManager::on_logging_out(bool is_logging_out) { void StateManager::add_callback(unique_ptr callback) { if (callback->on_network(network_type_, network_generation_) && callback->on_online(online_flag_) && - callback->on_state(get_real_state())) { + callback->on_state(get_real_state()) && callback->on_logging_out(is_logging_out_)) { callbacks_.push_back(std::move(callback)); } } diff --git a/td/telegram/StateManager.h b/td/telegram/StateManager.h index 92bf66c95..10f9e6aa7 100644 --- a/td/telegram/StateManager.h +++ b/td/telegram/StateManager.h @@ -109,7 +109,7 @@ class StateManager final : public Actor { uint32 network_generation_ = 1; bool online_flag_ = false; bool use_proxy_ = false; - bool is_logging_out_ = true; + bool is_logging_out_ = false; static constexpr double UP_DELAY = 0.05; static constexpr double DOWN_DELAY = 0.3; diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 1e1460eff..3fa41e0f7 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -569,19 +569,23 @@ void ConnectionCreator::on_online(bool online_flag) { online_flag_ = online_flag; if (need_drop_flood_control) { for (auto &client : clients_) { - client.second.sanity_flood_control.clear_events(); client.second.backoff.clear(); + client.second.sanity_flood_control.clear_events(); client.second.flood_control_online.clear_events(); client_loop(client.second); } } } void ConnectionCreator::on_logging_out(bool is_logging_out) { + if (is_logging_out_ == is_logging_out) { + return; + } + VLOG(connections) << "Receive logging out flag " << is_logging_out; is_logging_out_ = is_logging_out; for (auto &client : clients_) { - client.second.sanity_flood_control.clear_events(); client.second.backoff.clear(); + client.second.sanity_flood_control.clear_events(); client.second.flood_control_online.clear_events(); client_loop(client.second); } @@ -879,6 +883,9 @@ void ConnectionCreator::client_loop(ClientInfo &client) { return client_set_timeout_at(client, wakeup_at); } client.sanity_flood_control.add_event(static_cast(Time::now())); + if (!act_as_if_online) { + client.backoff.add_event(static_cast(Time::now())); + } // Create new RawConnection // sync part @@ -895,9 +902,6 @@ void ConnectionCreator::client_loop(ClientInfo &client) { // Events with failed socket creation are ignored flood_control.add_event(static_cast(Time::now())); - if (!act_as_if_online) { - client.backoff.add_event(static_cast(Time::now())); - } auto socket_fd = r_socket_fd.move_as_ok(); IPAddress debug_ip; diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index 52b87b5dc..4d4ab26b3 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -285,7 +285,7 @@ void Scheduler::do_event(ActorInfo *actor_info, Event &&event) { UNREACHABLE(); break; } - // can't clear event here. It may be already destroyed during destory_actor + // can't clear event here. It may be already destroyed during destroy_actor } void Scheduler::register_migrated_actor(ActorInfo *actor_info) {