sochix / TLSharp

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

Sometimes "Couldn't read the packet length" under Linux (.Net Core) #1013

Open mightywill opened 3 years ago

mightywill commented 3 years ago

When I try to send message from Kestrel webserver under Linux that was some time in idle state(no requests) then a first two attempts fail with "Couldn't read the packet length" or "Broken pipe" but the 3rd and the following succeed

Couldn't read the packet length

System.InvalidOperationException Couldn't read the packet length at TlSharp.TLSharp.Core.Network.TcpTransport.Receive(CancellationToken token) at TlSharp.TLSharp.Core.Network.MtProtoSender.Receive(TLMethod request, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.RequestWithDcMigration(TLMethod request, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.SendRequestAsync[T](TLMethod methodToExecute, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.SendAuthenticatedRequestAsync[T](TLMethod methodToExecute, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.GetUserDialogsAsync(Int32 offsetDate, Int32 offsetId, TLAbsInputPeer offsetPeer, Int32 limit, CancellationToken token)

mightywill commented 3 years ago

System.IO.IOException Unable to read data from the transport connection: Broken pipe. at TlSharp.TLSharp.Core.Network.TcpTransport.Send(Byte[] packet, CancellationToken token) at TlSharp.TLSharp.Core.Network.MtProtoSender.Send(Byte[] packet, TLMethod request, CancellationToken token) at TlSharp.TLSharp.Core.Network.MtProtoSender.Send(TLMethod request, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.RequestWithDcMigration(TLMethod request, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.SendRequestAsync[T](TLMethod methodToExecute, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.SendAuthenticatedRequestAsync[T](TLMethod methodToExecute, CancellationToken token) at TlSharp.TLSharp.Core.TelegramClient.GetUserDialogsAsync(Int32 offsetDate, Int32 offsetId, TLAbsInputPeer offsetPeer, Int32 limit, CancellationToken tok

novelhawk commented 3 years ago

Can reproduce on Windows 10 19042.746 with .NET Core 5.0.102 and TLSharp version 0.1.0.574 (NuGet). Happens frequently on multiple methods. (threw on ConnectAsync and SendCodeRequestAsync)

EDIT: I assume this is due to .NET Core and .NET Framework incompatibilities

MKalloub commented 3 years ago

Hi @novelhawk, @mightywill Same error I got on Windows Server 2016 with ASP.NET MVC app I'm using .NET framework 4.7.2, and TLSharp version 0.1.0.574 (NuGet) Mostly message sent, but sometime I got the following error

Couldn't read the packet length

at TLSharp.Core.Network.TcpTransport.d5.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.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.Network.MtProtoSender.d
8.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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.TelegramClient.d__11.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.ValidateEnd(Task task)

novelhawk commented 3 years ago

It seems that there are known incompatibilities in using this library in core environment. (See #687 #893 #763)