From 450b8393bc5a06fd1182690b967e8deb0c20b606 Mon Sep 17 00:00:00 2001 From: "Jeb.Wang" Date: Thu, 16 Jan 2025 10:50:57 +0800 Subject: [PATCH] Fix goroutine leaks * Fix goroutine leaks --- server/proxy/xtcp.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/proxy/xtcp.go b/server/proxy/xtcp.go index f69d0790..1ccf331c 100644 --- a/server/proxy/xtcp.go +++ b/server/proxy/xtcp.go @@ -17,8 +17,7 @@ package proxy import ( "fmt" "reflect" - - "github.com/fatedier/golib/errors" + "sync" v1 "github.com/fatedier/frp/pkg/config/v1" "github.com/fatedier/frp/pkg/msg" @@ -32,7 +31,8 @@ type XTCPProxy struct { *BaseProxy cfg *v1.XTCPProxyConfig - closeCh chan struct{} + closeCh chan struct{} + closeOnce sync.Once } func NewXTCPProxy(baseProxy *BaseProxy) Proxy { @@ -43,6 +43,7 @@ func NewXTCPProxy(baseProxy *BaseProxy) Proxy { return &XTCPProxy{ BaseProxy: baseProxy, cfg: unwrapped, + closeCh: make(chan struct{}), } } @@ -87,9 +88,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() { + pxy.closeOnce.Do(func() { + pxy.BaseProxy.Close() + pxy.rc.NatHoleController.CloseClient(pxy.GetName()) close(pxy.closeCh) }) }