Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Client stops dispatching events after receiving UpdatesTooLong update

Open hladkky opened this issue 3 years ago • 8 comments

Hello, I am developing the userbot that listens to the incoming messages and processes them. But it stops listening after receiving update with type UpdatesTooLong. I have noticed that in the logs, but I don't know how to wake up client to handle incoming messages again.

Code that causes the issue

from telethon import TelegramClient
...
client = TelegramClient(
    ...
)

@client.on(events.NewMessage())
def handle_message(event):
    # process event

try:
    client.start()
    client.run_until_disconnected()
...

Logs

DEBUG:telethon.network.mtprotosender:Handling update UpdatesTooLong

hladkky avatar May 13 '22 14:05 hladkky

Yeah I'm afraid I'll have to release another bugfix release in the v1 series… I wanted to get v2 earlier but that didn't happen. Not sure how to best do another release; I did not want to bump the minor version, but there's a layer update as well which I often release with a minor bump.

Lonami avatar May 13 '22 14:05 Lonami

@Lonami could you give me a hint how I can quickly deal with this problem, please?

hladkky avatar May 13 '22 14:05 hladkky

There is no "quick" solution I can think of.

Lonami avatar May 13 '22 14:05 Lonami

Well, thanks so much for your fast answer. I have figured out how to temporary fix this problem before opening issue, but I hoped that there would be better solution. I have patched _handle_update method of MTProtoSender and once I am receiving UpdatesTooLong, I call _start_reconnect so far. But there is a chance to miss some messages during the reconnect.

Hope you will manage with the problem and fix it with usage of getDifference rpc, as it is mentioned in official docs. Good luck!

hladkky avatar May 13 '22 14:05 hladkky

You're welcome to be my beta tester for the v1.24.0 branch which should eventually handle updatesTooLong by using getDifference. I happened to start working on it yesterday and it's mostly implemented (backported from v2) but may have some issues. You can try with:

pip3 install -U https://github.com/LonamiWebs/Telethon/archive/v1.24.zip

(I was not sure how long it would take me to get it to the point where it could be used, which is why I said there was no quick solution, but maybe the current changes are enough…)

Lonami avatar May 13 '22 15:05 Lonami

Unlikely, now it is not handles any message. Handlers are not processes new messages. Sometimes it randomly processes messages from the past

hladkky avatar May 13 '22 19:05 hladkky

That's definitely not what I experienced from my little testing on that branch, but maybe my session was fresh enough to not fail on catching up (assuming that was your issue).

Lonami avatar May 14 '22 07:05 Lonami

Definitely, yes. I tried to use catch up on my own, but result was particularly the same. Messages from the past were grabbed and passed to the handlers.

hladkky avatar May 14 '22 07:05 hladkky

Closing since the v1.25 version on PyPi has been released and should have most bugs ironed out (there are some issues but I plan to release a fix for those in the coming days).

Lonami avatar Sep 20 '22 12:09 Lonami