From a34ad57ee40e0d666d348e9b2e683e00a4464edd Mon Sep 17 00:00:00 2001 From: Noid Date: Mon, 27 May 2024 05:27:53 +0900 Subject: [PATCH 1/3] Fix: ValueError & ConnectionError on handle_packet https://github.com/pyrogram/pyrogram/issues/1263 --- pyrogram/session/session.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 4df65f5392..1ac9a7ad9c 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -185,14 +185,18 @@ async def restart(self): await self.start() async def handle_packet(self, packet): - data = await self.loop.run_in_executor( - pyrogram.crypto_executor, - mtproto.unpack, - BytesIO(packet), - self.session_id, - self.auth_key, - self.auth_key_id - ) + try: + data = await self.loop.run_in_executor( + pyrogram.crypto_executor, + mtproto.unpack, + BytesIO(packet), + self.session_id, + self.auth_key, + self.auth_key_id + ) + except (ValueError, ConnectionError) as e: + log.info(e.args[0]) + return messages = ( data.body.messages From 5ffc6e35c197bc3a63cef29bd3011821bcc0e0b6 Mon Sep 17 00:00:00 2001 From: Noid Date: Mon, 27 May 2024 05:30:07 +0900 Subject: [PATCH 2/3] Fix: RuntimeError on recv --- pyrogram/connection/transport/tcp/tcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 82ef033be4..73b5c743a4 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -112,7 +112,7 @@ async def recv(self, length: int = 0): self.reader.read(length - len(data)), TCP.TIMEOUT ) - except (OSError, asyncio.TimeoutError): + except (OSError, asyncio.TimeoutError, RuntimeError): return None else: if chunk: From 8ff2b502764b42c614f992d5a49ea2bbcf0d678e Mon Sep 17 00:00:00 2001 From: Noid Date: Mon, 27 May 2024 08:50:27 +0900 Subject: [PATCH 3/3] FIx: AttributeError on recv Logging: ```2024-05-27 07:25:20,740 - asyncio - ERROR - Task exception was never retrieved future: exception=AttributeError("'NoneType' object has no attribute 'read'")> Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyrogram/session/session.py", line 305, in recv_worker packet = await self.connection.recv() File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/connection.py", line 72, in recv return await self.protocol.recv() File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp_abridged.py", line 46, in recv length = await super().recv(1) File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp.py", line 112, in recv self.reader.read(length - len(data)), AttributeError: 'NoneType' object has no attribute 'read'``` --- pyrogram/connection/transport/tcp/tcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 73b5c743a4..4d307a2224 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -112,7 +112,7 @@ async def recv(self, length: int = 0): self.reader.read(length - len(data)), TCP.TIMEOUT ) - except (OSError, asyncio.TimeoutError, RuntimeError): + except (OSError, asyncio.TimeoutError, RuntimeError, AttributeError): return None else: if chunk: