fix: 优化C# IPC客户端连接逻辑,避免管道破裂异常#238
Merged
Merged
Conversation
Comment on lines
+471
to
+474
| except asyncio.CancelledError: | ||
| pass | ||
| except Exception as e: | ||
| logger.exception(f"C# IPC 客户端循环出错: {e}") | ||
| logger.warning(f"C# IPC 客户端循环出错: {e}") |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 通过为 Python 侧 C# IPC 客户端增加“连接失败自动重试”的机制,降低当 ClassIsland(IPC 服务端)未启动/未就绪时触发 Pipe is broken 等异常的概率,从而让客户端在服务端可用前更平滑地等待与重连。
Changes:
- 在
_run_client()内新增connect_with_retry(),对IpcClient.Connect()+Wait()封装并在失败时按固定间隔重试。 - 将初始连接与断线后的重连流程统一改为调用
connect_with_retry()。 - 将客户端主循环的异常日志由
exception调整为warning。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+416
to
+427
| 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) |
|
|
||
| task = self.ipc_client.Connect() | ||
| await self.loop.run_in_executor(None, lambda: task.Wait()) | ||
| if not await connect_with_retry(): |
Comment on lines
+473
to
+474
| except Exception as e: | ||
| logger.exception(f"C# IPC 客户端循环出错: {e}") | ||
| logger.warning(f"C# IPC 客户端循环出错: {e}") |
Collaborator
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/906f3972-4681-4831-bb96-ce2e602f11e4 Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/906f3972-4681-4831-bb96-ce2e602f11e4 Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Contributor
已按该评审线程完成修复并推送,提交为 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
此PR解决了当ClassIsland(C# IPC服务端)未运行或未准备好时,Python IPC客户端尝试连接导致
AggregateException: Pipe is broken的问题。变更内容:
_run_client中引入了一个异步辅助函数connect_with_retry(),用于封装IpcClient.Connect()调用。connect_with_retry()会在连接失败时捕获异常,记录警告日志,并以5秒的间隔重试,直到连接成功或程序停止运行。connect_with_retry(),确保客户端能够优雅地等待服务端可用。AggregateException的日志级别从ERROR降级为WARNING,以避免在ClassIsland未运行时产生不必要的错误报告,因为这是一种预期情况。Fixes SECRANDOM-7T