From e3a8a781d3833196e61904fe5276b3838d7233f0 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 1 Mar 2025 00:38:17 +0300 Subject: [PATCH] Attempt to fix handler is closed Signed-off-by: wulan17 --- pyrogram/connection/transport/tcp/tcp.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index d948b6d2..3e403b33 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -134,12 +134,14 @@ class TCP: await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT) except Exception as e: log.info("Close exception: %s %s", type(e).__name__, e) + finally: + self.writer = None async def send(self, data: bytes) -> None: - if self.writer is None: - return None - async with self.lock: + if self.writer is None or self.writer.is_closing(): + return None + try: self.writer.write(data) await self.writer.drain()