Skip to content

Commit

Permalink
Retry if initial ping has unexpected response
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 1, 2023
1 parent 4e53a43 commit 08a543e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mautrix_twitter/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import asyncio
import logging

import aiohttp

from mautrix.appservice import DOUBLE_PUPPET_SOURCE_KEY
from mautrix.bridge import BaseUser, async_getter_lock
from mautrix.errors import MNotFound
Expand Down Expand Up @@ -200,7 +202,20 @@ async def _connect(self, auth_token: str | None = None, csrf_token: str | None =
client.set_tokens(auth_token or self.auth_token, csrf_token or self.csrf_token)

# Initial ping to make sure auth works
await client.get_user_identifier()
initial_ping_retry = 0
while True:
try:
await client.get_user_identifier()
break
except aiohttp.ClientResponseError as e:
if e.status == 403 and initial_ping_retry < 5:
initial_ping_retry += 1
self.log.warning(
"Unexpected 403 in initial ping, retrying in 5 seconds", exc_info=True
)
await asyncio.sleep(5)
else:
raise

self.client = client
self.client.add_handler(Conversation, self.handle_conversation_update)
Expand Down

0 comments on commit 08a543e

Please sign in to comment.