TgSharp icon indicating copy to clipboard operation
TgSharp copied to clipboard

File located on a different DC

Open ReshetovAnton opened this issue 3 years ago • 1 comments

I have a problem. If, when trying to send a request TLRequestGetUserPhotos, the user's photo is located on another DC, the library will migrate the user to the required DC. But on the next request, there will already be a user_migration_error error. The current library functionality in the ReconnectToDcAsync method does not solve this problem in any way.

I came to a solution, just skip files that are on a different DC.

private async Task RequestWithDcMigration(TLMethod request, CancellationToken token = default(CancellationToken), int attempt = 0)
        {
            if (sender == null)
                throw new InvalidOperationException("Not connected!");

            var completed = false;
            while (!completed)
            {
                try
                {
                    await sender.Send(request, token).ConfigureAwait(false);
                    await sender.Receive(request, token).ConfigureAwait(false);
                    completed = true;
                }
                catch (DataCenterMigrationException e)
                {
                    //File located on a different DC:
                    if(e.Message.IndexOf("File located on a different DC:") != -1)
                        throw new Exception("naher nado poka");
                    if (Session.DataCenter.DataCenterId.HasValue &&
                        Session.DataCenter.DataCenterId.Value == e.DC)
                    {
                        throw new Exception($"Telegram server replied requesting a migration to DataCenter {e.DC} when this connection was already using this DataCenter", e);
                    }

                    await ReconnectToDcAsync(e.DC, token).ConfigureAwait(false);
                    // prepare the request for another try
                    request.ConfirmReceived = false;
                }
            }
        }

Help please, can anyone come across this.

ReshetovAnton avatar Oct 07 '21 19:10 ReshetovAnton

Hi! I fixed it in this commit https://github.com/SmaGMan/TgSharp/commit/f081731eb1a5db225e4524d1cb9f1fcaf9dcb582

SmaGMan avatar Nov 02 '21 09:11 SmaGMan