diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index b0cd89b62..d754adbf2 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -1070,7 +1070,8 @@ void Session::connection_open_finish(ConnectionInfo *info, info->state = ConnectionInfo::State::Ready; info->created_at = Time::now_cached(); info->wakeup_at = Time::now_cached() + 10; - if (unknown_queries_.size() > 1024) { + if (unknown_queries_.size() > MAX_INFLIGHT_QUERIES) { + LOG(ERROR) << "With current limits `Too much queries with unknown state` error must be impossible"; on_session_failed(Status::Error("Too much queries with unknown state")); return; } @@ -1311,12 +1312,12 @@ void Session::loop() { while (main_connection_.state == ConnectionInfo::State::Ready) { if (auth_data_.is_ready(Time::now_cached())) { if (need_send_query()) { - while (!pending_queries_.empty()) { + while (!pending_queries_.empty() && sent_queries_.size() < MAX_INFLIGHT_QUERIES) { auto &query = pending_queries_.front(); connection_send_query(&main_connection_, std::move(query)); pending_queries_.pop_front(); + need_flush = true; } - need_flush = true; } if (need_send_bind_key()) { // send auth.bindTempAuthKey diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index 128aa1e4f..b7e292454 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -157,6 +157,7 @@ class Session final bool close_flag_ = false; static constexpr double ACTIVITY_TIMEOUT = 60 * 5; + static constexpr size_t MAX_INFLIGHT_QUERIES = 1024; struct ContainerInfo { size_t ref_cnt;