-
Notifications
You must be signed in to change notification settings - Fork 377
disconnection without possibility to reconnect #930
Description
the production code i am running is conceptually as simple as this:
while(stayLive)
{
if(!client.IsConnected)
await client.ConnectAsync();
jf(!client.IsUserAuthenticated())
{ ...} // auth process
// do the dirty job
}
the thing is that there are two issues:
-
client.IsConnected always returns true, unless it's fixed with my previous fix by adding a check on null on sender in IsConnected
-
if for any reason the tcpClient in TcpTransport becomes disconnected, there is no way to reconnect it and the Send method will always throw an exception (below)
I propose to remove the tcpClient initialization in TcpTransport from the constructor and automatically reconnect the tcpClient if it's disconnected rather than throwing the exception
System.InvalidOperationException: Client not connected to server.
at TgSharp.Core.Network.TcpTransport.d__4.MoveNext() in \TgSharp\src\TgSharp.Core\Network\TcpTransport.cs:line 39
--- 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.ConfiguredTaskAwaiter.GetResult()
at TgSharp.Core.Network.MtProtoSender.d__6.MoveNext() in \TgSharp\src\TgSharp.Core\Network\MtProtoSender.cs:line 100
--- 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.ConfiguredTaskAwaiter.GetResult()
at TgSharp.Core.Network.MtProtoSender.d__5.MoveNext() in \TgSharp\src\TgSharp.Core\Network\MtProtoSender.cs:line 62
--- 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.ConfiguredTaskAwaiter.GetResult()
at TgSharp.Core.TelegramClient.d__12.MoveNext() in \TgSharp\src\TgSharp.Core\TelegramClient.cs:line 106
--- 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 GroupCasher.GroupManager.d__17.MoveNext() in C:\Users\mengh\source\repos\GroupCasher\GroupCasher\GroupManager.cs:line 125