Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Telethon stops responding after repeated [client.updates] Timeout waiting for updates expired

Open SajjadMomen opened this issue 7 months ago • 1 comments

[DEBUG] telethon.client.updates: Timeout waiting for updates expired

Expected behavior

Telethon should continue to handle updates and respond to API requests (such as get_me(), send_message(), etc.) even after periods of inactivity or high message traffic.

Specifically, seeing the log line:

[DEBUG] telethon.client.updates: Timeout waiting for updates expired

…should not cause the client to stop processing further updates or become unresponsive.

Reproduction steps

Unfortunately, I don’t have a minimal script yet, but here’s the general setup:

  1. Create a Telethon client connected to a user or bot account.
  2. Start py-tgcalls for group voice streaming (running on the same event loop).
  3. Let the bot run for ~30–60 minutes in a moderately active chat.
  4. Eventually, the above log message starts repeating.
  5. After that, the bot no longer responds to any Telethon API calls, even though the event loop is still running.

A restart of the process restores normal behavior temporarily.

Actual behavior

Summary

I'm encountering an issue where Telethon becomes unresponsive and stops handling further API requests after repeatedly logging the following debug message:

[DEBUG] telethon.client.updates: Timeout waiting for updates expired

Once this message starts appearing, my bot no longer responds to any Telethon operations — including get_me(), send_message(), and even get_dialogs(). The only solution is to restart the process.

Context

I'm using Telethon along with py-tgcalls (for group voice streaming). The issue typically appears after some runtime (30–60 minutes), especially under higher load or activity.

Observations

  • The logs are flooded with Timeout waiting for updates expired.
  • py-tgcalls still runs, but Telethon doesn't seem to process any further events.
  • Restarting the event loop (i.e., restarting the bot) resolves it temporarily.
  • I suspect that the update mechanism or internal state may be locked or stalled.

Reproduction

Although I haven't found a minimal reproducible script yet, the issue seems more likely to happen when:

  1. There are active group calls.
  2. Telethon is under load (many updates/messages).
  3. py-tgcalls is interacting with the same event loop.

Versions

  • Telethon: 1.40.0
  • py-tgcalls: 2.2.0rc3
  • Python: 3.12
  • OS: Ubuntu 22

Any suggestions?

Let me know if there's any way to detect or avoid this state programmatically — or if it's worth isolating in a minimal example. I'm happy to help debug further.

Thanks for your work!

Traceback

No response

Telethon version

1.40.0

Python version

3.12.3

Operating system (including distribution name and version)

Ubuntu 22.04.5 LTS

Other details

No response

Checklist

  • [x] The error is in the library's code, and not in my own.
  • [x] I have searched for this issue before posting it and there isn't an open duplicate.
  • [x] I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

SajjadMomen avatar May 23 '25 21:05 SajjadMomen

Appreciate the detailed report, unfortunately don't think I'll look into this any time soon. I would be surprised if Telethon is getting "locked up" though, as I'd expect to have heard about it sooner. If pings are still going out and being answered periodically, the library continues to work just fine.

Maybe periodically calling client.get_difference will help, maybe not.

Lonami avatar May 24 '25 07:05 Lonami