Skip to content

Commit

Permalink
fix(parsing/message): uncaught TimedOutError (503)
Browse files Browse the repository at this point in the history
Signed-off-by: Rongrong <i@rong.moe>
  • Loading branch information
Rongronggg9 committed Nov 10, 2023
1 parent e09cc83 commit 4134ba2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/parsing/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
from telethon.tl import types, functions
from telethon.errors.rpcbaseerrors import TimedOutError
from telethon.errors.rpcerrorlist import SlowModeWaitError, FloodWaitError, ServerError
from telethon.utils import get_message_id
from collections import defaultdict
Expand Down Expand Up @@ -95,6 +96,7 @@ async def send_messages(self):

class Message:
no_retry = False
max_tries = 2 * 2 # telethon internally tries twice
__overall_concurrency = 30
__overall_semaphore = asyncio.BoundedSemaphore(__overall_concurrency)

Expand All @@ -113,7 +115,7 @@ def __init__(self,
self.media_type = media_type
self.link_preview = link_preview
self.silent = silent
self.retries = 0
self.tries = 0

self.attributes = (
(types.DocumentAttributeVideo(0, 0, 0),)
Expand Down Expand Up @@ -169,16 +171,19 @@ async def send(self, reply_to: Union[int, types.Message, None] = None) \
# logger.error(f'Msg dropped due to lock acquisition timeout ({self.user_id})')
# return None
except (FloodWaitError, SlowModeWaitError) as e:
# telethon has retried for us, but we release locks and retry again here to see if it will be better
if self.retries >= 1:
# telethon internally catches these errors and retries for us
self.tries += 2
if self.tries >= self.max_tries:
logger.error(f'Msg dropped due to too many flood control retries ({self.user_id})')
return None

self.retries += 1
await locks.user_flood_wait_background(self.user_id, seconds=e.seconds) # acquire a flood wait
except ServerError as e:
# telethon has retried for us, so we just retry once more
if self.retries >= 1:
# telethon internally catches this error and retries for us
self.tries += 2
if self.tries >= self.max_tries:
raise e
except TimedOutError as e:
# telethon does not catch this error or retry for us, so we do it ourselves
self.tries += 1
if self.tries >= self.max_tries:
raise e

self.retries += 1

0 comments on commit 4134ba2

Please sign in to comment.