Fix goroutine leaks

This commit is contained in:
Jeb.Wang 2025-01-15 19:02:46 +08:00
parent 93289aab03
commit 881f21431d

View File

@ -17,6 +17,7 @@ package proxy
import (
"fmt"
"reflect"
"sync"
"github.com/fatedier/golib/errors"
@ -33,6 +34,7 @@ type XTCPProxy struct {
cfg *v1.XTCPProxyConfig
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())
pxy.closeOnce.Do(func() {
_ = errors.PanicToError(func() {
close(pxy.closeCh)
})
})
}