Skip to content

Commit

Permalink
Add quick retries when connecting to Telegram (#941)
Browse files Browse the repository at this point in the history
* Add quick 5 retries when connecting to Telegram

* Fix attempt initialisation

Co-authored-by: Tulir Asokan <tulir@maunium.net>

* Log only when retrying

Co-authored-by: Tulir Asokan <tulir@maunium.net>

---------

Co-authored-by: Tulir Asokan <tulir@maunium.net>
  • Loading branch information
Fizzadar and tulir authored Nov 13, 2023
1 parent 2a67c96 commit 1b2f07d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mautrix_telegram/abstract_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,16 @@ async def has_full_access(self, allow_bot: bool = False) -> bool:
async def start(self, delete_unless_authenticated: bool = False) -> AbstractUser:
if not self.client:
await self._init_client()
await self.client.connect()
attempts = 1
while True:
try:
await self.client.connect()
except Exception:
attempts += 1
if attempts > 10:
raise
self.log.exception("Exception connecting to Telegram, retrying in 5s...")
await asyncio.sleep(5)
self.log.debug(f"{'Bot' if self.is_relaybot else self.mxid} connected: {self.connected}")
return self

Expand Down

0 comments on commit 1b2f07d

Please sign in to comment.