Skip to content

[WIP] Fix potential crash when multiple TcpClient/UdpClient share an EventLoop#811

Closed
Copilot wants to merge 1 commit intomasterfrom
copilot/fix-tcpclient-udpclient-eventloop
Closed

[WIP] Fix potential crash when multiple TcpClient/UdpClient share an EventLoop#811
Copilot wants to merge 1 commit intomasterfrom
copilot/fix-tcpclient-udpclient-eventloop

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 10, 2026

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>多个TcpClient/UdpClient共用一个EventLoop,析构时有概率崩溃</issue_title>
<issue_description>Image
Image</issue_description>

<agent_instructions>Please analyze and respond to this issue.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ithewei 退出线程时应该等待IO线程结束,return 0前,加 ``` loopThread.stop(); loopThread.join(); ``` 试试 @ithewei 最新master分支上有个修复,看看带上没https://github.com/ithewei/libhv/commit/41c63bfbf0e4817711febfbe695609d524d4af85 @ithewei 是的,这种方式必须十分小心TcpClient/UdpClient的生命周期,最好的实践是使用堆对象,然后调用loop->runInLoop{delete cli;}在事件循环所在线程里删除对象,参考这个示例程序 https://github.com/ithewei/libhv/blob/master/evpp/TcpClientEventLoop_test.cpp @ithewei > 是的,这种方式必须十分小心TcpClient/UdpClient的生命周期,最好的实践是使用堆对象,然后调用loop->runInLoop{delete cli;}在事件循环所在线程里删除对象,参考这个示例程序 https://github.com/ithewei/libhv/blob/master/evpp/TcpClientEventLoop_test.cpp

参考这个结论,最佳实践是在loop所在线程去析构TcpClient/UdpClient对象</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@ithewei
Copy link
Copy Markdown
Owner

ithewei commented Mar 11, 2026

@copilot try again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

多个TcpClient/UdpClient共用一个EventLoop,析构时有概率崩溃

2 participants