From 5d804cc0848567a851ab452fbd65ef89cdeec666 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 15:07:35 +0000 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96C#=20IPC=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E8=BF=9E=E6=8E=A5=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E7=AE=A1=E9=81=93=E7=A0=B4=E8=A3=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/IPC_URL/csharp_ipc_handler.py | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/common/IPC_URL/csharp_ipc_handler.py b/app/common/IPC_URL/csharp_ipc_handler.py index 6a4aced3..f9f75e19 100644 --- a/app/common/IPC_URL/csharp_ipc_handler.py +++ b/app/common/IPC_URL/csharp_ipc_handler.py @@ -407,6 +407,26 @@ def _on_class_test(self): def _run_client(self): """运行 C# IPC 客户端""" + async def connect_with_retry(retry_delay: float = 5.0) -> bool: + """尝试连接 ClassIsland IPC 服务端,失败时自动重试,直到连接成功或停止运行。 + + Returns: + True 表示连接成功,False 表示 is_running 变为 False 而退出。 + """ + while self.is_running: + try: + task = self.ipc_client.Connect() + await self.loop.run_in_executor( + None, lambda task=task: task.Wait() + ) + return True + except Exception as e: + logger.warning( + f"C# IPC 连接失败(ClassIsland 可能未运行),{retry_delay:.0f}s 后重试: {e}" + ) + await asyncio.sleep(retry_delay) + return False + async def client(): """异步客户端""" @@ -416,8 +436,8 @@ async def client(): Action(lambda: self._on_class_test()), ) - task = self.ipc_client.Connect() - await self.loop.run_in_executor(None, lambda: task.Wait()) + if not await connect_with_retry(): + return self.is_connected = True logger.debug("C# IPC 连接成功!") @@ -430,10 +450,8 @@ async def client(): logger.debug("C# IPC 断连!重连...") self.is_connected = False - task = self.ipc_client.Connect() - await self.loop.run_in_executor( - None, lambda task=task: task.Wait() - ) + if not await connect_with_retry(): + break self.is_connected = True logger.debug("C# IPC 连接成功!") elif not self._no_plugin_logged: @@ -453,7 +471,7 @@ async def client(): except asyncio.CancelledError: pass except Exception as e: - logger.exception(f"C# IPC 客户端循环出错: {e}") + logger.warning(f"C# IPC 客户端循环出错: {e}") finally: self.loop.close() self.loop = None From 24e28758e1109c2676750bffc984492fb044f15d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 15:22:42 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86IPC=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=8F=96=E6=B6=88=E4=B8=8E=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/906f3972-4681-4831-bb96-ce2e602f11e4 Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com> --- app/common/IPC_URL/csharp_ipc_handler.py | 62 +++++++++++++----------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/app/common/IPC_URL/csharp_ipc_handler.py b/app/common/IPC_URL/csharp_ipc_handler.py index f9f75e19..fc02052d 100644 --- a/app/common/IPC_URL/csharp_ipc_handler.py +++ b/app/common/IPC_URL/csharp_ipc_handler.py @@ -420,11 +420,16 @@ async def connect_with_retry(retry_delay: float = 5.0) -> bool: None, lambda task=task: task.Wait() ) return True + except asyncio.CancelledError: + return False except Exception as e: logger.warning( f"C# IPC 连接失败(ClassIsland 可能未运行),{retry_delay:.0f}s 后重试: {e}" ) - await asyncio.sleep(retry_delay) + try: + await asyncio.sleep(retry_delay) + except asyncio.CancelledError: + return False return False async def client(): @@ -436,32 +441,33 @@ async def client(): Action(lambda: self._on_class_test()), ) - if not await connect_with_retry(): - return - self.is_connected = True - logger.debug("C# IPC 连接成功!") - - while self.is_running: - await asyncio.sleep(1) - - # logger.debug(f"stat: plugin({self._check_plugin_alive()}) ci({self._check_ci_alive()})") - if not self.check_plugin_alive(): - if not self.check_ci_alive(): - logger.debug("C# IPC 断连!重连...") - self.is_connected = False - - if not await connect_with_retry(): - break - self.is_connected = True - logger.debug("C# IPC 连接成功!") - elif not self._no_plugin_logged: - logger.debug("未安装 SecRandom-Ci 插件。") - self._no_plugin_logged = True - else: - self._no_plugin_logged = False - - self.ipc_client = None - self.is_connected = False + try: + if not await connect_with_retry(): + return + self.is_connected = True + logger.debug("C# IPC 连接成功!") + + while self.is_running: + await asyncio.sleep(1) + + # logger.debug(f"stat: plugin({self._check_plugin_alive()}) ci({self._check_ci_alive()})") + if not self.check_plugin_alive(): + if not self.check_ci_alive(): + logger.debug("C# IPC 断连!重连...") + self.is_connected = False + + if not await connect_with_retry(): + break + self.is_connected = True + logger.debug("C# IPC 连接成功!") + elif not self._no_plugin_logged: + logger.debug("未安装 SecRandom-Ci 插件。") + self._no_plugin_logged = True + else: + self._no_plugin_logged = False + finally: + self.ipc_client = None + self.is_connected = False # 启动新的 asyncio 事件循环 self.loop = asyncio.new_event_loop() @@ -471,7 +477,7 @@ async def client(): except asyncio.CancelledError: pass except Exception as e: - logger.warning(f"C# IPC 客户端循环出错: {e}") + logger.exception(f"C# IPC 客户端循环出错: {e}") finally: self.loop.close() self.loop = None From 28cea7adb1b951fd2317c47b11de3e29c8821397 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 15:24:03 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E8=AE=A9IPC=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=BC=82=E5=B8=B8=E6=AD=A3=E7=A1=AE=E4=BC=A0?= =?UTF-8?q?=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/906f3972-4681-4831-bb96-ce2e602f11e4 Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com> --- app/common/IPC_URL/csharp_ipc_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/IPC_URL/csharp_ipc_handler.py b/app/common/IPC_URL/csharp_ipc_handler.py index fc02052d..909f12a7 100644 --- a/app/common/IPC_URL/csharp_ipc_handler.py +++ b/app/common/IPC_URL/csharp_ipc_handler.py @@ -421,7 +421,7 @@ async def connect_with_retry(retry_delay: float = 5.0) -> bool: ) return True except asyncio.CancelledError: - return False + raise except Exception as e: logger.warning( f"C# IPC 连接失败(ClassIsland 可能未运行),{retry_delay:.0f}s 后重试: {e}" @@ -429,7 +429,7 @@ async def connect_with_retry(retry_delay: float = 5.0) -> bool: try: await asyncio.sleep(retry_delay) except asyncio.CancelledError: - return False + raise return False async def client():