Reset TelegramClient completely on AuthKeyDuplicatedError

This commit is contained in:
Tulir Asokan
2021-08-16 20:54:02 +03:00
parent 3ab5e4d8cc
commit 13cac8db9a
2 changed files with 11 additions and 5 deletions
+7 -1
View File
@@ -210,7 +210,13 @@ class User(AbstractUser, BaseUser):
self.log.warning("Got AuthKeyDuplicatedError in start()")
await self.push_bridge_state(BridgeStateEvent.BAD_CREDENTIALS,
error="tg-auth-key-duplicated")
# Don't return, let the session be deleted if delete_unless_authenticated is true
await self.client.disconnect()
self.client.session.delete()
self.client = None
if not delete_unless_authenticated:
# The caller wants the client to be connected, so restart the connection.
await super().start()
return self
except Exception:
await self.push_bridge_state(BridgeStateEvent.UNKNOWN_ERROR)
raise