From afb7c5f56d9ac3195214fa56423daf58a377792a Mon Sep 17 00:00:00 2001 From: Flowseal Date: Sun, 22 Mar 2026 08:00:14 +0300 Subject: [PATCH] revert keepalive mechanism --- proxy/tg_ws_proxy.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/proxy/tg_ws_proxy.py b/proxy/tg_ws_proxy.py index 0c5427b..b6e5539 100644 --- a/proxy/tg_ws_proxy.py +++ b/proxy/tg_ws_proxy.py @@ -145,7 +145,6 @@ _st_I_net = struct.Struct('!I') _st_Ih = struct.Struct('ws ended: %s", label, e) async def ws_to_tcp(): - nonlocal down_bytes, down_packets, last_recv_time + nonlocal down_bytes, down_packets try: while True: data = await ws.recv() if data is None: break - last_recv_time = asyncio.get_event_loop().time() n = len(data) _stats.bytes_down += n down_bytes += n @@ -666,29 +663,11 @@ async def _bridge_ws(reader, writer, ws: RawWebSocket, label, except Exception as e: log.debug("[%s] ws->tcp ended: %s", label, e) - async def ws_keepalive(): - try: - while not ws._closed: - await asyncio.sleep(2) - idle = asyncio.get_event_loop().time() - last_recv_time - if idle >= 2 and not ws._closed: - try: - ws.writer.write(_WS_PING_FRAME) - await ws.writer.drain() - log.debug("[%s] %s WS PING (idle %.1fs)", - label, dc_tag, idle) - except Exception: - break - except asyncio.CancelledError: - pass - - ka_task = asyncio.create_task(ws_keepalive()) tasks = [asyncio.create_task(tcp_to_ws()), asyncio.create_task(ws_to_tcp())] try: await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED) finally: - ka_task.cancel() for t in tasks: t.cancel() for t in tasks: