Change condition to perform automatic reconnection

This commit is contained in:
Lonami Exo 2017-09-30 18:33:34 +02:00
parent b6bc9ac39b
commit 933ae01d85

View File

@ -374,6 +374,7 @@ class TelegramBareClient:
timeout=self._sender.connection.get_timeout() timeout=self._sender.connection.get_timeout()
) )
client.connect(_exported_auth=export_auth, _sync_updates=False) client.connect(_exported_auth=export_auth, _sync_updates=False)
client._authorized = True # We exported the auth, so we got auth
return client return client
def _get_cdn_client(self, cdn_redirect): def _get_cdn_client(self, cdn_redirect):
@ -396,7 +397,8 @@ class TelegramBareClient:
# #
# This relies on the fact that TelegramBareClient._dc_options is # This relies on the fact that TelegramBareClient._dc_options is
# static and it won't be called from this DC (it would fail). # static and it won't be called from this DC (it would fail).
client.connect(cdn=True) # Avoid invoking non-CDN specific methods client.connect(_cdn=True) # Avoid invoking non-CDN specific methods
client._authorized = self._authorized
return client return client
# endregion # endregion
@ -481,8 +483,9 @@ class TelegramBareClient:
pass # We will just retry pass # We will just retry
except ConnectionResetError: except ConnectionResetError:
if self._reconnect_lock.locked(): if not self._authorized or self._reconnect_lock.locked():
# We are connecting and we don't want to reconnect there... # Only attempt reconnecting if we're authorized and not
# reconnecting already.
raise raise
self._logger.debug('Server disconnected us. Reconnecting and ' self._logger.debug('Server disconnected us. Reconnecting and '