Skip to content
This repository was archived by the owner on Dec 5, 2021. It is now read-only.
This repository was archived by the owner on Dec 5, 2021. It is now read-only.

disconnection without possibility to reconnect #930

@solarin

Description

@solarin

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:

  1. client.IsConnected always returns true, unless it's fixed with my previous fix by adding a check on null on sender in IsConnected

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions