Fix cancelling a None handle on first connection+error

This commit is contained in:
Lonami Exo 2018-06-21 09:48:11 +02:00
parent cfa5cd0db2
commit a99fce471a

View File

@ -155,13 +155,16 @@ class MTProtoSender:
self._pending_ack.clear() self._pending_ack.clear()
self._last_ack = None self._last_ack = None
if self._send_loop_handle:
__log__.debug('Cancelling the send loop...') __log__.debug('Cancelling the send loop...')
self._send_loop_handle.cancel() self._send_loop_handle.cancel()
if self._recv_loop_handle:
__log__.debug('Cancelling the receive loop...') __log__.debug('Cancelling the receive loop...')
self._recv_loop_handle.cancel() self._recv_loop_handle.cancel()
__log__.info('Disconnection from {} complete!'.format(self._ip)) __log__.info('Disconnection from {} complete!'.format(self._ip))
if self._disconnected:
if error: if error:
self._disconnected.set_exception(error) self._disconnected.set_exception(error)
else: else:
@ -252,11 +255,10 @@ class MTProtoSender:
__log__.debug('New auth_key attempt {}...'.format(retry)) __log__.debug('New auth_key attempt {}...'.format(retry))
self.state.auth_key, self.state.time_offset =\ self.state.auth_key, self.state.time_offset =\
await authenticator.do_authentication(plain) await authenticator.do_authentication(plain)
break
except (SecurityError, AssertionError) as e: except (SecurityError, AssertionError) as e:
__log__.warning('Attempt {} at new auth_key failed: {}' __log__.warning('Attempt {} at new auth_key failed: {}'
.format(retry, e)) .format(retry, e))
else:
break
else: else:
e = ConnectionError('auth_key generation failed {} times' e = ConnectionError('auth_key generation failed {} times'
.format(self._retries)) .format(self._retries))