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,17 +155,20 @@ class MTProtoSender:
self._pending_ack.clear() self._pending_ack.clear()
self._last_ack = None self._last_ack = None
__log__.debug('Cancelling the send loop...') if self._send_loop_handle:
self._send_loop_handle.cancel() __log__.debug('Cancelling the send loop...')
self._send_loop_handle.cancel()
__log__.debug('Cancelling the receive loop...') if self._recv_loop_handle:
self._recv_loop_handle.cancel() __log__.debug('Cancelling the receive loop...')
self._recv_loop_handle.cancel()
__log__.info('Disconnection from {} complete!'.format(self._ip)) __log__.info('Disconnection from {} complete!'.format(self._ip))
if error: if self._disconnected:
self._disconnected.set_exception(error) if error:
else: self._disconnected.set_exception(error)
self._disconnected.set_result(None) else:
self._disconnected.set_result(None)
def send(self, request, ordered=False): def send(self, request, ordered=False):
""" """
@ -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))