sochix / TLSharp

Telegram client library implemented in C#
1k stars 380 forks source link

UserMigrationException xxxmigrationexception #839

Closed lazyjohny500 closed 5 years ago

lazyjohny500 commented 5 years ago

I got error: TLSharp.Core.Network.UserMigrationException: 'User located on a different DC: 4. See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error'

I add the stacktrace as you ask in the readme image

knocte commented 5 years ago

Please paste whole ex.ToString()

lazyjohny500 commented 5 years ago
TLSharp.Core.Network.UserMigrationException: User located on a different DC: 4. See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error
   at TLSharp.Core.Network.MtProtoSender.HandleRpcResult(UInt64 messageId, Int32 sequence, BinaryReader messageReader, TLMethod request) in \Telegram\TLSharp-master\TLSharp.Core\Network\MtProtoSender.cs:line 301
   at TLSharp.Core.Network.MtProtoSender.processMessage(UInt64 messageId, Int32 sequence, BinaryReader messageReader, TLMethod request) in \Telegram\TLSharp-master\TLSharp.Core\Network\MtProtoSender.cs:line 201
   at TLSharp.Core.Network.MtProtoSender.<Receive>d__8.MoveNext() in \Telegram\TLSharp-master\TLSharp.Core\Network\MtProtoSender.cs:line 139
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at TLSharp.Core.TelegramClient.<RequestWithDcMigration>d__11.MoveNext() in \Telegram\TLSharp-master\TLSharp.Core\TelegramClient.cs:line 120
knocte commented 5 years ago

I don't understand, TelegramClient.cs line 120 is inside a try{}catch block that should have captured this exception.

lazyjohny500 commented 5 years ago

That's correct. It caught on line 120 (its not crashing) but than its make a loop of retrying: Got "USER_MIGRATE_4" throw new UserMigrationException In RequestWithDcMigration

while(!completed){
await _sender.Receive(request);
}

catch and again ReconnectToDcAsync

So I can't understand what happening

lazyjohny500 commented 5 years ago

803 Looks like it's similar to what happen here:

Sorry! actually the await client.ConnectAsync not responding. I debug (telegramclient.cs) that and find that while on executing the line await _sender.Receive(invokewithLayer); - is not responding (means await for infinite time!) the same with await client.GetContactsAsync

What is the problem with - await _sender.Receive(invokewithLayer); which is worked properly till 10 days ago?

knocte commented 5 years ago

Right, there have been reports of infinite loops around that code. But I can't understand why the switch to a different DC can still respond with the same error.

lazyjohny500 commented 5 years ago

Is there a chance that my user is blocked? But on the telegram web everything is working correctly.

knocte commented 5 years ago

@lazyjohny500 thanks for reporting this bug, I've committed something which I think would fix the infinite loop (even if it doesn't fix the underlying issue yet).

Can you try latest master, and if you see different behaviour, create a new bug with the new exception please?

knocte commented 5 years ago

(FTR the commit was 60a3c6235792163e9c74e9c24b1ca7800a220ce2 )

lazyjohny500 commented 5 years ago

The same loop. Because _session.DataCenter.DataCenterId.HasValue is False So it's not enter to your scope

                    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);
                    }
AzazelloKAY commented 5 years ago

Have same problem: infinite loop with UserMigrateException after getting image not from my native DC. image receiving; make next req(anything); in RequestWithDcMigration() in "await _sender.Receive(request)" get UserMigrateException then go to "catch" and "await ReconnectToDcAsync(e.DC);" when ReconnectToDcAsync method makes his ExportAuthorization and "exported = await SendRequestAsync<..>(..)" this SendRequestAsync again call RequestWithDcMigration which again gets same exception.... loop

Check "_session.DataCenter.DataCenterId.HasValue" doesn't work because of DataCenter constructor: DataCenter (int? dcId, string address, int port) dcId is null on start.

knocte commented 5 years ago

@AzazelloKAY if you find a solution, please post a PullRequest, thanks

AzazelloKAY commented 5 years ago

@knocte I`m work with TLsharp fork for .net core. My solution is based on

https://core.telegram.org/api/optimisation: We recommend that separate connections and sessions be created for these tasks. Remember that the extra sessions must be deleted when no longer needed.

and this repo:

https://github.com/ilyalatt/Telega/blob/ccc85e0e510532e15830f4ce688a651e7bdfba84/Telega/TelegramClient.cs FileSessionStore mechanics

So, when i need to get a file:

Important! fileClien has different SessionStore then mainClient (actually i`m not store this session at all) to avoid changes in mainClient session.

Such export doesn't kill my main session.