From 52f7c8f0641982d1ec397c9649482fedf6b4c371 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 17 May 2017 14:01:58 +0300 Subject: [PATCH] Mark connection as inited only on a non-error response. --- Telegram/SourceFiles/mtproto/connection.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 3c04d7c26..4aec60677 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -1848,9 +1848,14 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr response.resize(end - from); memcpy(response.data(), from, (end - from) * sizeof(mtpPrime)); } - if (!sessionData->layerWasInited()) { - sessionData->setLayerWasInited(true); - sessionData->owner()->notifyLayerInited(true); + if (typeId != mtpc_rpc_error) { + // An error could be some RPC_CALL_FAIL or other error inside + // the initConnection, so we're not sure yet that it was inited. + // Wait till a good response is received. + if (!sessionData->layerWasInited()) { + sessionData->setLayerWasInited(true); + sessionData->owner()->notifyLayerInited(true); + } } auto requestId = wasSent(reqMsgId.v);