Fix disconnection without a previous connection

This commit is contained in:
Lonami Exo 2019-05-11 16:49:38 +02:00
parent b31b239088
commit c1be0bd2e8

View File

@ -251,12 +251,17 @@ class MTProtoSender:
self._log.info('Connection to %s complete!', self._connection) self._log.info('Connection to %s complete!', self._connection)
async def _disconnect(self, error=None): 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._log.info('Disconnecting from %s...', self._connection)
self._user_connected = False self._user_connected = False
try: try:
self._log.debug('Closing current connection...') self._log.debug('Closing current connection...')
await self._connection.disconnect() await self._connection.disconnect()
finally: finally:
self._connection = None
self._log.debug('Cancelling {} pending message(s)...' self._log.debug('Cancelling {} pending message(s)...'
.format(len(self._pending_state))) .format(len(self._pending_state)))
for state in self._pending_state.values(): for state in self._pending_state.values():