Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Fix issue with leaving session in a invalid state if GetFile throws an exception after reconnecting to another DC #548

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions TLSharp.Core/TelegramClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,24 @@ public async Task<TLFile> GetFile(TLAbsInputFileLocation location, int filePartS
var serverPort = _session.Port;

await ReconnectToDcAsync(ex.DC);
var auth = await SendRequestAsync<TLAuthorization>(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<TLAuthorization>(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;
Expand Down