From 93289aab032745125297c735ce4dac9a59b40367 Mon Sep 17 00:00:00 2001 From: "Jeb.Wang" Date: Wed, 15 Jan 2025 17:14:31 +0800 Subject: [PATCH 1/2] Fix goroutine leaks --- server/proxy/xtcp.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/proxy/xtcp.go b/server/proxy/xtcp.go index f69d0790..bac7349e 100644 --- a/server/proxy/xtcp.go +++ b/server/proxy/xtcp.go @@ -43,6 +43,7 @@ func NewXTCPProxy(baseProxy *BaseProxy) Proxy { return &XTCPProxy{ BaseProxy: baseProxy, cfg: unwrapped, + closeCh: make(chan struct{}), } } From 881f21431d312885d54bd471e8849eabce6216b0 Mon Sep 17 00:00:00 2001 From: "Jeb.Wang" Date: Wed, 15 Jan 2025 19:02:46 +0800 Subject: [PATCH 2/2] Fix goroutine leaks --- server/proxy/xtcp.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/proxy/xtcp.go b/server/proxy/xtcp.go index bac7349e..4c555de2 100644 --- a/server/proxy/xtcp.go +++ b/server/proxy/xtcp.go @@ -17,6 +17,7 @@ package proxy import ( "fmt" "reflect" + "sync" "github.com/fatedier/golib/errors" @@ -32,7 +33,8 @@ type XTCPProxy struct { *BaseProxy cfg *v1.XTCPProxyConfig - closeCh chan struct{} + closeCh chan struct{} + closeOnce sync.Once } func NewXTCPProxy(baseProxy *BaseProxy) Proxy { @@ -90,7 +92,9 @@ func (pxy *XTCPProxy) Run() (remoteAddr string, err error) { func (pxy *XTCPProxy) Close() { pxy.BaseProxy.Close() pxy.rc.NatHoleController.CloseClient(pxy.GetName()) - _ = errors.PanicToError(func() { - close(pxy.closeCh) + pxy.closeOnce.Do(func() { + _ = errors.PanicToError(func() { + close(pxy.closeCh) + }) }) }