From 8ee0757b593e3f463a241dfceb1b75e45cf8d84a Mon Sep 17 00:00:00 2001 From: Aleksandr Kalashnikov <33665156+sleep3r@users.noreply.github.com> Date: Fri, 12 Jun 2026 20:13:29 +0300 Subject: [PATCH] MtProtoKit: apply salt from bad_server_salt for normal requests, not only the time-fix ping fixes the infinite Connecting/Updating on iOS after backgrounding (telemt/telemt#582) --- submodules/MtProtoKit/Sources/MTProto.m | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/submodules/MtProtoKit/Sources/MTProto.m b/submodules/MtProtoKit/Sources/MTProto.m index 71ac74b7471..fa979f07171 100644 --- a/submodules/MtProtoKit/Sources/MTProto.m +++ b/submodules/MtProtoKit/Sources/MTProto.m @@ -2501,17 +2501,20 @@ - (void)_processIncomingMessage:(MTIncomingMessage *)incomingMessage totalSize:( if ([badMsgNotification isKindOfClass:[MTBadServerSaltNotificationMessage class]]) { + // The server delivers a valid salt (nextServerSalt) inside the authenticated AES-IGE + // envelope, so it is equally trustworthy whether it rejects an ordinary request or the + // dedicated time-fix ping. Apply it directly. Previously a salt that rejected a normal + // request was discarded and the session entered MTProtoStateAwaitingTimeFixAndSalts + // (which gates every outgoing transaction); if the follow-up time-fix ping was then + // lost, nothing re-applied the salt or re-armed a transaction, so the session wedged + // until the DC closed the socket (~90-120s, surfaced to the user as a stuck "Updating"). if (_timeFixContext != nil && badMessageId == _timeFixContext.messageId) - { _timeFixContext = nil; - - int64_t validSalt = ((MTBadServerSaltNotificationMessage *)badMsgNotification).nextServerSalt; - NSTimeInterval timeDifference = incomingMessage.messageId / 4294967296.0 - [[NSDate date] timeIntervalSince1970]; - [self completeTimeSync]; - [self timeSyncInfoChanged:timeDifference saltList:@[[[MTDatacenterSaltInfo alloc] initWithSalt:validSalt firstValidMessageId:incomingMessage.messageId lastValidMessageId:incomingMessage.messageId + (4294967296 * 30 * 60)]] authInfoSelector:authInfoSelector]; - } - else - [self initiateTimeSync]; + + int64_t validSalt = ((MTBadServerSaltNotificationMessage *)badMsgNotification).nextServerSalt; + NSTimeInterval timeDifference = incomingMessage.messageId / 4294967296.0 - [[NSDate date] timeIntervalSince1970]; + [self completeTimeSync]; + [self timeSyncInfoChanged:timeDifference saltList:@[[[MTDatacenterSaltInfo alloc] initWithSalt:validSalt firstValidMessageId:incomingMessage.messageId lastValidMessageId:incomingMessage.messageId + (4294967296 * 30 * 60)]] authInfoSelector:authInfoSelector]; } else {