From d6818f25f547d2fde537e88633f8583371663211 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 20 Jun 2018 21:12:47 +0200 Subject: [PATCH] Fix rare iter_dialogs infinite loop --- telethon/client/dialogs.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index 142fd5d4..b726e364 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -107,6 +107,12 @@ class DialogMethods(UserMethods): req.offset_date = r.messages[-1].date req.offset_peer = entities[utils.get_peer_id(r.dialogs[-1].peer)] + if req.offset_id == r.messages[-1].id: + # In some very rare cases this will get stuck in an infinite + # loop, where the offsets will get reused over and over. If + # the new offset is the same as the one before, break already. + break + req.offset_id = r.messages[-1].id req.exclude_pinned = True