TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

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

Open esavkin opened this issue 7 years ago • 13 comments

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.<Receieve>d__4.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.Network.MtProtoPlainSender.<Receive>d__7.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.<ConnectAsync>d__9.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.<ReconnectToDcAsync>d__10.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.<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.TaskAwaiter`1.GetResult() at ChatWorker.Extensions.TelegramClientEx.<GetPhotoAndSave>d__1.MoveNext()

trace for Can't decode packet at TLSharp.Core.Network.MtProtoSender.DecodeMessage(Byte[] body) at TLSharp.Core.Network.MtProtoSender.<Receive>d__9.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.<ConnectAsync>d__9.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.TaskAwaiter`1.GetResult() at ChatWorker.Extensions.TelegramClientEx.<GetPhotoAndSave>d__1.MoveNext()

esavkin avatar Jul 29 '17 21:07 esavkin

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<TLPhotoSize>().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

Hvzh avatar Aug 03 '17 06:08 Hvzh

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

esavkin avatar Aug 03 '17 08:08 esavkin

No, never

чт, 3 авг. 2017 г., 11:04 Evgeny Savkin [email protected]:

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 .

Hvzh avatar Aug 03 '17 14:08 Hvzh

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

andreysolovyov avatar Oct 09 '17 16:10 andreysolovyov

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

samuelg78 avatar Oct 11 '17 05:10 samuelg78

@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.

knocte avatar Oct 11 '17 05:10 knocte

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.

1g0r avatar Dec 26 '17 11:12 1g0r

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?

knocte avatar Dec 26 '17 11:12 knocte

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.

1g0r avatar Dec 26 '17 12:12 1g0r

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

amiroveisi avatar Jan 27 '18 12:01 amiroveisi

I get the same promlem at #851

emreordukaya avatar May 07 '19 20:05 emreordukaya

I get the same promlem at #851

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

ofcerci4826 avatar Feb 17 '21 11:02 ofcerci4826

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Çİ [email protected] 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.

emreordukaya avatar Feb 17 '21 20:02 emreordukaya