diff --git a/tdnet/td/net/GetHostByNameActor.cpp b/tdnet/td/net/GetHostByNameActor.cpp index fdef46f64..b431938d1 100644 --- a/tdnet/td/net/GetHostByNameActor.cpp +++ b/tdnet/td/net/GetHostByNameActor.cpp @@ -171,15 +171,16 @@ void GetHostByNameActor::run(string host, int port, bool prefer_ipv6, Promise res) mutable { send_closure(actor_id, &GetHostByNameActor::on_result, std::move(host), prefer_ipv6, std::move(res)); @@ -191,14 +192,16 @@ void GetHostByNameActor::on_result(std::string host, bool prefer_ipv6, Resultsecond; - CHECK(!value.promises.empty()); - CHECK(!value.query.empty()); + auto query_it = active_queries_[prefer_ipv6].find(host); + CHECK(query_it != active_queries_[prefer_ipv6].end()); + auto &query = query_it->second; + CHECK(!query.promises.empty()); + CHECK(!query.query.empty()); - auto promises = std::move(value.promises); + auto promises = std::move(query.promises); auto end_time = Time::now() + (res.is_ok() ? options_.ok_timeout : options_.error_timeout); value = Value{std::move(res), end_time}; - CHECK(value.promises.empty()); - CHECK(value.query.empty()); + active_queries_[prefer_ipv6].erase(query_it); for (auto &promise : promises) { promise.second.set_result(value.get_ip_port(promise.first)); diff --git a/tdnet/td/net/GetHostByNameActor.h b/tdnet/td/net/GetHostByNameActor.h index 1104f8fae..859e8ee9a 100644 --- a/tdnet/td/net/GetHostByNameActor.h +++ b/tdnet/td/net/GetHostByNameActor.h @@ -42,13 +42,12 @@ class GetHostByNameActor final : public Actor { static TD_WARN_UNUSED_RESULT ActorOwn<> resolve(std::string host, ResolveOptions options, Promise promise); private: + void on_result(std::string host, bool prefer_ipv6, Result res); + struct Value { Result ip; double expire_at; - ActorOwn<> query; - std::vector>> promises; - Value(Result ip, double expire_at) : ip(std::move(ip)), expire_at(expire_at) { } @@ -62,9 +61,13 @@ class GetHostByNameActor final : public Actor { }; std::unordered_map cache_[2]; - Options options_; + struct Query { + ActorOwn<> query; + std::vector>> promises; + }; + std::unordered_map active_queries_[2]; - void on_result(std::string host, bool prefer_ipv6, Result res); + Options options_; }; } // namespace td