From 84ec2a5f7494ffc2516ecc78ef89aba3da199b33 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 22 May 2024 21:18:42 +0400 Subject: [PATCH] Possibly fix wrong requests order. --- Telegram/SourceFiles/mtproto/mtp_instance.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 76c5cb623e318..ee10958370136 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -1020,11 +1020,24 @@ void Instance::Private::sendRequest( const auto signedDcId = toMainDc ? -realShiftedDcId : realShiftedDcId; registerRequest(requestId, signedDcId); + request->lastSentTime = crl::now(); + request->needsLayer = needsLayer; + if (afterRequestId) { request->after = getRequest(afterRequestId); + + if (request->after) { + // Check if this after request is waiting in _dependentRequests. + // This happens if it was after some other request and failed + // to wait for it, but that other request is still processed. + QMutexLocker locker(&_dependentRequestsLock); + const auto i = _dependentRequests.find(afterRequestId); + if (i != end(_dependentRequests)) { + _dependentRequests.emplace(requestId, afterRequestId); + return; + } + } } - request->lastSentTime = crl::now(); - request->needsLayer = needsLayer; session->sendPrepared(request, msCanWait); }