Skip to content

Commit

Permalink
Fix goroutine leaks
Browse files Browse the repository at this point in the history
* Fix goroutine leaks
  • Loading branch information
Alpha2J authored Jan 16, 2025
1 parent 27db621 commit 450b839
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/proxy/xtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -43,6 +43,7 @@ func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
return &XTCPProxy{
BaseProxy: baseProxy,
cfg: unwrapped,
closeCh: make(chan struct{}),
}
}

Expand Down Expand Up @@ -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)
})
}

0 comments on commit 450b839

Please sign in to comment.