-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解决goroutine泄漏问题 #4638
解决goroutine泄漏问题 #4638
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
func (pxy *XTCPProxy) Close() {
pxy.BaseProxy.Close()
pxy.rc.NatHoleController.CloseClient(pxy.GetName())
_ = errors.PanicToError(func() {
close(pxy.closeCh)
})
} Could you also update this to use |
Sure, I've updated the code to use |
Just remove it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
WHY
由于
closeCh
没有被初始化,在Close()
函数中执行close(pxy.closeCh)
的时候,会panic:"panic error: close of nil channel";导致无法退出Run()
函数中创建的goroutine,造成goroutine泄漏,同时引发内存泄漏;在我的案例中,client用户单实例大概4000,运行两天,阻塞在case <-pxy.closeCh
中的goroutine达到三万多;