From c304ee903f0b990fbc40ee91d7f943e15db937a6 Mon Sep 17 00:00:00 2001 From: Goblenus Date: Fri, 16 Jun 2017 15:59:10 +0300 Subject: [PATCH] Trigger reconnection on BrokenPipeError and InvalidChecksumError --- telethon/telegram_client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index d49b5855..0644d898 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -11,7 +11,7 @@ from .errors import (RPCError, UnauthorizedError, InvalidParameterError, ReadCancelledError, FileMigrateError, PhoneMigrateError, NetworkMigrateError, UserMigrateError, PhoneCodeEmptyError, PhoneCodeExpiredError, PhoneCodeHashEmptyError, - PhoneCodeInvalidError) + PhoneCodeInvalidError, InvalidChecksumError) # For sending and receiving requests from .tl import MTProtoRequest, Session, JsonSession @@ -817,6 +817,14 @@ class TelegramClient(TelegramBareClient): except ReadCancelledError: self._logger.info('Receiving updates cancelled') + except BrokenPipeError: + self._logger.info('Tcp session is broken. Reconnecting...') + self.reconnect() + + except InvalidChecksumError: + self._logger.info('MTProto session is broken. Reconnecting...') + self.reconnect() + except OSError: self._logger.warning('OSError on updates thread, %s logging out', 'was' if self.sender.logging_out else 'was not')