Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnecting after one or two hours #83

Open
derodevil opened this issue Jan 8, 2022 · 11 comments
Open

Disconnecting after one or two hours #83

derodevil opened this issue Jan 8, 2022 · 11 comments

Comments

@derodevil
Copy link

derodevil commented Jan 8, 2022

IDisposable KeepAlive(TelegramClient tg) => Observable
            .Timer(dueTime: TimeSpan.Zero, period: TimeSpan.FromSeconds(10))
            .Select(_ => Observable.FromAsync(() => tg.Call(new Telega.Rpc.Dto.Functions.Ping(pingId: 0))).Materialize())
            .Concat()
            .Subscribe();

The above snippet doesn't work. My winforms application gets disconnected after 1 to 2 hours inactivity.

[EDIT]
I try my own custom ping every ten seconds. After approximately an hour it generates error as follows:

Telega.TgInternalException: Telega internal exception. Unhandled exception. See an inner exception. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 91.108.56.156:443
   at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- 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 Telega.Connect.TgConnectionEstablisher.<CreateTcpClient>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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Telega.Connect.TgConnectionEstablisher.<EstablishConnection>d__1.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 Telega.Connect.TgConnectionPool.<ReConnect>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 Telega.Connect.TgBellhop.<ChangeConn>d__15.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 Telega.Connect.TgBellhop.<CallWithReConnect>d__19`1.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 Telega.Connect.TgBellhop.<CallWithMigration>d__20`1.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 Telega.TaskWrapper.<Wrap>d__2`1.MoveNext()
   --- End of inner exception stack trace ---
   at Telega.TaskWrapper.<Wrap>d__2`1.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 TestTelegram.MainUi.<Ping>d__11.MoveNext()
@ilyalatt
Copy link
Owner

Hello. Looks like you use preview version of 0.5.0. Try to update the library.

@derodevil
Copy link
Author

derodevil commented Jan 15, 2022

Is this code still needed or you have updated the library where it keeps alive without the code? IDisposable KeepAlive(TelegramClient tg) =>

@ilyalatt
Copy link
Owner

ilyalatt commented Jan 15, 2022 via email

@derodevil
Copy link
Author

I use the latest version 0.5.1 started at 17:45 and I let it idle for more than two hours. At 21:00 I send a text message and it couldn't receive any massage. I don't think the latest version keep it alive. My code looks like this:

var contacts = await tg.Contacts.GetContacts();
... some logic with `contacts`

KeepAlive(tg); //where the `KeepAlive` is the above snippet

tg.Updates.Stream.Subscribe(
	onNext: async n =>
	{
		try
		{
			... my other code when receiving a message
		}
		catch (Exception ex)
		{
			WriteLog(ex.Message)
		}
	},
	onError: e =>
	{
		WriteLog(e.Message);
	}
);

@ilyalatt
Copy link
Owner

Hm. Can you subscribe to internal exceptions? Should look like tg.Updates.Exceptions.Subscribe(Console.WriteLine). KeepAlive snippet just ignores ping exceptions. Replace .Subscribe() with .Select(x => x.Exception).Where(x => x != null).Subscribe(Console.WriteLine). It should give more information for debugging.

@derodevil
Copy link
Author

derodevil commented Jan 16, 2022

I had been running from 11pm to 7am and no exception was caught. I've checked the log file since I put the error message to a file and nothing there.

[EDIT]
I think I find the problem here where the tg.Updates and/or KeepAlive method should not be placed inside a multi threaded method. I tried this approach and it keeps alive for more than two hours

@ilyalatt
Copy link
Owner

Yet another reason to move KeepAlive into the library internals

@derodevil
Copy link
Author

Well, I'm waiting for the next release

@derodevil
Copy link
Author

Do you have any updates for this issue?

@ilyalatt
Copy link
Owner

Do you have any updates for this issue?

Not yet. I had started the refactoring and abandoned it. I do not have time for Telega now and the next few months. I can review and merge a PR however.

@derodevil
Copy link
Author

Hi.. I'm still waiting 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants