Trigger reconnection on BrokenPipeError and InvalidChecksumError

This commit is contained in:
Goblenus 2017-06-16 15:59:10 +03:00 committed by Lonami
parent 92b4125b2b
commit c304ee903f

View File

@ -11,7 +11,7 @@ from .errors import (RPCError, UnauthorizedError, InvalidParameterError,
ReadCancelledError, FileMigrateError, PhoneMigrateError, ReadCancelledError, FileMigrateError, PhoneMigrateError,
NetworkMigrateError, UserMigrateError, PhoneCodeEmptyError, NetworkMigrateError, UserMigrateError, PhoneCodeEmptyError,
PhoneCodeExpiredError, PhoneCodeHashEmptyError, PhoneCodeExpiredError, PhoneCodeHashEmptyError,
PhoneCodeInvalidError) PhoneCodeInvalidError, InvalidChecksumError)
# For sending and receiving requests # For sending and receiving requests
from .tl import MTProtoRequest, Session, JsonSession from .tl import MTProtoRequest, Session, JsonSession
@ -817,6 +817,14 @@ class TelegramClient(TelegramBareClient):
except ReadCancelledError: except ReadCancelledError:
self._logger.info('Receiving updates cancelled') 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: except OSError:
self._logger.warning('OSError on updates thread, %s logging out', self._logger.warning('OSError on updates thread, %s logging out',
'was' if self.sender.logging_out else 'was not') 'was' if self.sender.logging_out else 'was not')