Skip to content

File located on a different DC #52

@ReshetovAnton

Description

@ReshetovAnton

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions