diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 287826815..eb2acab21 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -718,12 +718,11 @@ void ConnectionCreator::on_network(bool network_flag, uint32 network_generation) auto old_generation = network_generation_; network_generation_ = network_generation; if (network_flag_) { - if (old_generation != network_generation_) { - VLOG(connections) << "Set proxy query token to 0: " << old_generation << " " << network_generation_; - resolve_proxy_query_token_ = 0; - resolve_proxy_timestamp_ = Timestamp(); - get_proxy_info_timestamp_ = Timestamp(); - } + VLOG(connections) << "Set proxy query token to 0: " << old_generation << " " << network_generation_; + resolve_proxy_query_token_ = 0; + resolve_proxy_timestamp_ = Timestamp(); + get_proxy_info_timestamp_ = Timestamp(); + for (auto &client : clients_) { client.second.backoff.clear(); client.second.flood_control.clear_events(); @@ -1300,6 +1299,9 @@ void ConnectionCreator::loop() { if (!is_inited_) { return; } + if (G()->close_flag()) { + return; + } if (!network_flag_) { return; } @@ -1344,14 +1346,14 @@ void ConnectionCreator::loop() { } void ConnectionCreator::on_result(NetQueryPtr query) { - if (get_link_token() != get_proxy_info_query_token_) { - return; - } - SCOPE_EXIT { loop(); }; + if (get_link_token() != get_proxy_info_query_token_) { + return; + } + get_proxy_info_query_token_ = 0; auto res = fetch_result(std::move(query)); if (res.is_error()) { @@ -1407,16 +1409,16 @@ void ConnectionCreator::schedule_get_proxy_info(int32 expires) { } void ConnectionCreator::on_proxy_resolved(Result r_ip_address, bool dummy) { + SCOPE_EXIT { + loop(); + }; + if (get_link_token() != resolve_proxy_query_token_) { VLOG(connections) << "Ignore unneeded proxy IP address " << get_link_token() << ", expected " << resolve_proxy_query_token_; return; } - SCOPE_EXIT { - loop(); - }; - resolve_proxy_query_token_ = 0; if (r_ip_address.is_error()) { VLOG(connections) << "Receive error for resolving proxy IP address: " << r_ip_address.error();