Skip to content

Commit 1972df6

Browse files
author
Pyrogram-Mod - Dev
committed
fix(session): wait for reconnect before retrying on OSError
When the TCP handler is closed, invoke() retried immediately while the restart was still pending, burning through all retries before the session came back up. Now waits on is_started before each retry. Closes #18
1 parent 6178df5 commit 1972df6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pyrogram/session/session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ async def invoke(
542542
query_name, str(e) or repr(e)
543543
)
544544

545-
await asyncio.sleep(0.5)
545+
# Wait for the session to come back up before retrying,
546+
# otherwise all retries burn out while the reconnect is still pending.
547+
if isinstance(e, OSError):
548+
try:
549+
await asyncio.wait_for(self.is_started.wait(), timeout=self.WAIT_TIMEOUT)
550+
except asyncio.TimeoutError:
551+
pass
552+
else:
553+
await asyncio.sleep(0.5)
546554

547555
raise TimeoutError("Exceeded maximum number of retries")

0 commit comments

Comments
 (0)