sochix / TLSharp

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

Couldn't read the packet length -> Can't decode packet" #536

Open esavkin opened 7 years ago

esavkin commented 7 years ago

like #384

code: var resFile = await client.GetFile(new TLInputFileLocation() { local_id = location.local_id, secret = location.secret, volume_id = location.volume_id }, 1024 * 64);

After several successful photo downloads I'm getting the following exception: Couldn't read the packet length after that exception, on next call client.GetFile I'm always getting next exception: Can't decode packet after that exception all calls **client.*** methods fail with exception "Can't decode packet" Only after removed session file connection can be successfully established.

I think client.GetFile with exception set session file to corrupt state

Trace for Couldn't read the packet length: at TLSharp.Core.Network.TcpTransport.d4.MoveNext() --- 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.Network.MtProtoPlainSender.d7.MoveNext() --- 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.TaskAwaiter1.GetResult() at TLSharp.Core.Auth.Authenticator.<DoAuthentication>d__0.MoveNext() --- 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.TaskAwaiter1.GetResult() at TLSharp.Core.TelegramClient.d9.MoveNext() --- 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.d10.MoveNext() --- 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.GetResult() at TLSharp.Core.TelegramClient.d25.MoveNext() --- 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 ChatWorker.Extensions.TelegramClientEx.d1.MoveNext()

trace for Can't decode packet at TLSharp.Core.Network.MtProtoSender.DecodeMessage(Byte[] body) at TLSharp.Core.Network.MtProtoSender.d9.MoveNext() --- 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.d9.MoveNext() --- 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.TaskAwaiter1.GetResult() at TLSharp.Core.TelegramClient.<GetFile>d__25.MoveNext() --- 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.TaskAwaiter1.GetResult() at ChatWorker.Extensions.TelegramClientEx.d__1.MoveNext()

Hvzh commented 7 years ago

Hello, This is the code I use for reaqding pictures from chat:

`var tLMessageMediaPhoto = (TLMessageMediaPhoto)message.media;

var photo = (TLPhoto)tLMessageMediaPhoto.photo;

var photoSize = photo.sizes.lists.OfType().Last(); TLFileLocation tf = (TLFileLocation)photoSize.location; var resFile = await client.GetFile(new TLInputFileLocation { local_id = tf.local_id, secret = tf.secret, volume_id = tf.volume_id }, 0, -1); ` I read up to 700 photos in cycle and never had any problems

esavkin commented 7 years ago

Hvzh, did you try to read chat/user avatar, not pictures from chat?

Hvzh commented 7 years ago

No, never

чт, 3 авг. 2017 г., 11:04 Evgeny Savkin notifications@github.com:

Hvzh, did you try to read chat/user avatar, not pictures from chat?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sochix/TLSharp/issues/536#issuecomment-319898529, or mute the thread https://github.com/notifications/unsubscribe-auth/AQJkxFmc1tX0pAhst9SAO2dI8oxsqboYks5sUX8AgaJpZM4OnePb .

andreysolovyov commented 6 years ago

I seems, that issue linked to DC migration problem. After failing getfile method with unexpected exception sessionStorage did not restored correct ip address.

samuelg78 commented 6 years ago

Me too getting the "Couldn't read the packet length" error very frequently. Anyway solution?

knocte commented 6 years ago

@samuelg78 if somebody knew a solution, it would have been fixed already. Please debug the problem and propose a bugfix in the form of a pull request.

1g0r commented 6 years ago

I'v got the same problem. It turned out that the problem was in closed tcp connection like described here https://social.msdn.microsoft.com/Forums/en-US/c857cad5-2eb6-4b6c-b0b5-7f4ce320c5cd/c-how-to-determine-if-a-tcpclient-has-been-disconnected?forum=netfxnetcom For me the solution was to override IsConnected property of the TLSharp.Core.TelegramClient class to check if the connection was actually closed.

Hope this will help to fix the problem.

knocte commented 6 years ago

For me the solution was to override IsConnected property of the TLSharp.Core.TelegramClient class to check if the connection was actually closed.

How did you do that?

1g0r commented 6 years ago

I've wrote proxy that encapsulates TelegramClient and overrides IsConnected like so: if (client.Client.Poll(0, SelectMode.SelectRead)) { byte[] buff = new byte[1]; if (client.Client.Receive(buff, SocketFlags.Peek) == 0) { return false; } } return true;

Where client is instance of the TcpClient class.

amiroveisi commented 6 years ago

@1g0r may i ask how did you initialized your TcpConnection? what's IP/Port for 'client'?

emreordukaya commented 5 years ago

I get the same promlem at #851

ofcerci4826 commented 3 years ago

I get the same promlem at #851

Selam Emre, Bende aynı problemi yaşıyorum bu problemi aşabildin mi ?

emreordukaya commented 3 years ago

Postu okumussundur detaylıca. Sistem çalışıyordu. Sadece belli mesajların resmi olunca gocuyordu. En son resmi iptal ettim çözemedik. 17 Şub 2021 ÖS 2:25 tarihinde Osman Fahri ÇERÇİ notifications@github.com yazdı:

I get the same promlem at #851

Selam Emre, Bende aynı problemi yaşıyorum bu problemi aşabildin mi ?

—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.