Skip to content

Commit

Permalink
Handle ConnectionError during update handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Oct 25, 2022
1 parent 2ffac2d commit 0c86806
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions telethon/client/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ async def _update_loop(self: 'TelegramClient'):
self._log[__name__].info('Cannot get difference since the account is not logged in: %s', type(e).__name__)
self._message_box.end_difference()
continue
except OSError as e:
# Network is likely down, but it's unclear for how long.
# If disconnect is called this task will be cancelled along with the sleep.
# If disconnect is not called, getting difference should be retried after a few seconds.
self._log[__name__].info('Cannot get difference since the network is down: %s: %s', type(e).__name__, e)
await asyncio.sleep(5)
continue
updates, users, chats = self._message_box.apply_difference(diff, self._mb_entity_cache)
if updates:
self._log[__name__].info('Got difference for account updates')
Expand Down Expand Up @@ -351,6 +358,13 @@ async def _update_loop(self: 'TelegramClient'):
self._mb_entity_cache
)
continue
except OSError as e:
self._log[__name__].info(
'Cannot get difference for channel %d since the network is down: %s: %s',
get_diff.channel.channel_id, type(e).__name__, e
)
await asyncio.sleep(5)
continue

updates, users, chats = self._message_box.apply_channel_difference(get_diff, diff, self._mb_entity_cache)
if updates:
Expand Down

0 comments on commit 0c86806

Please sign in to comment.