From 4146459be2f9a8a88ec9b5cd2c4040bf460ac89f Mon Sep 17 00:00:00 2001 From: Mike Manley Date: Fri, 11 Aug 2017 17:46:56 -0700 Subject: [PATCH] If we've reconnected to another DC during GetFile, ensure we always reconnect to original DC even if there is an exception --- TLSharp.Core/TelegramClient.cs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index a8f8842d..f66ae0a5 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -329,20 +329,24 @@ public async Task GetFile(TLAbsInputFileLocation location, int filePartS var serverPort = _session.Port; await ReconnectToDcAsync(ex.DC); - var auth = await SendRequestAsync(new TLRequestImportAuthorization - { - bytes = exportedAuth.bytes, - id = exportedAuth.id - }); - result = await GetFile(location, filePartSize, offset); - - _session.AuthKey = authKey; - _session.TimeOffset = timeOffset; - _transport = new TcpTransport(serverAddress, serverPort); - _session.ServerAddress = serverAddress; - _session.Port = serverPort; - await ConnectAsync(); - + try + { + var auth = await SendRequestAsync(new TLRequestImportAuthorization + { + bytes = exportedAuth.bytes, + id = exportedAuth.id + }); + result = await GetFile(location, filePartSize, offset); + } + finally + { + _session.AuthKey = authKey; + _session.TimeOffset = timeOffset; + _transport = new TcpTransport(serverAddress, serverPort); + _session.ServerAddress = serverAddress; + _session.Port = serverPort; + await ConnectAsync(); + } } return result;