From c1be0bd2e8bde8230b8209760c0fc939c145fb61 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 11 May 2019 16:49:38 +0200 Subject: [PATCH] Fix disconnection without a previous connection --- telethon/network/mtprotosender.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 9672c5a3..4f15b8e4 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -251,12 +251,17 @@ class MTProtoSender: self._log.info('Connection to %s complete!', self._connection) async def _disconnect(self, error=None): + if self._connection is None: + self._log.info('Not disconnecting (already have no connection)') + return + self._log.info('Disconnecting from %s...', self._connection) self._user_connected = False try: self._log.debug('Closing current connection...') await self._connection.disconnect() finally: + self._connection = None self._log.debug('Cancelling {} pending message(s)...' .format(len(self._pending_state))) for state in self._pending_state.values():