From d78a9e9d658892a2de157bfff2cad423ad3f5940 Mon Sep 17 00:00:00 2001 From: fengcaiwen <895703375@qq.com> Date: Mon, 19 Feb 2024 21:54:42 +0800 Subject: [PATCH] fix: close too many udp conn --- cmd/sshvpn/main.go | 2 +- go.mod | 2 +- go.sum | 2 ++ pkg/client/udphandler.go | 7 +++---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/sshvpn/main.go b/cmd/sshvpn/main.go index c91a98e..71a665a 100644 --- a/cmd/sshvpn/main.go +++ b/cmd/sshvpn/main.go @@ -23,7 +23,7 @@ func main() { func NewTunnelCommand() *cobra.Command { return &cobra.Command{ - Use: "tunnel", + Use: "sshvpn", Short: "connect to remote network", Long: ` connect to remote network. diff --git a/go.mod b/go.mod index 0c59892..3a6267a 100755 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 - github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240217121107-1f32a129b698 + github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240219134652-6e679cc2f189 golang.org/x/crypto v0.18.0 golang.org/x/net v0.20.0 gvisor.dev/gvisor v0.0.0-20230603040744-5c9219dedd33 diff --git a/go.sum b/go.sum index e9a045c..c0439a2 100755 --- a/go.sum +++ b/go.sum @@ -879,6 +879,8 @@ github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240217103841-597023bdeabb h1:aHJJ0W github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240217103841-597023bdeabb/go.mod h1:zQ0OPDSjBv24+nfsWtNcb94fowfjk2i5bBSt1dBIfwE= github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240217121107-1f32a129b698 h1:0qg7Xm5dmb4J8H+0SskgY+/YXXViNVEvtjMJxLvaI5M= github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240217121107-1f32a129b698/go.mod h1:zQ0OPDSjBv24+nfsWtNcb94fowfjk2i5bBSt1dBIfwE= +github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240219134652-6e679cc2f189 h1:xsC1bc95FrPIPL45JGPX/MKULg8wQRCBPtHG3TkSgMo= +github.com/wencaiwulue/kubevpn/v2 v2.2.3-0.20240219134652-6e679cc2f189/go.mod h1:zQ0OPDSjBv24+nfsWtNcb94fowfjk2i5bBSt1dBIfwE= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= diff --git a/pkg/client/udphandler.go b/pkg/client/udphandler.go index 21ad6c2..a0cd597 100644 --- a/pkg/client/udphandler.go +++ b/pkg/client/udphandler.go @@ -50,9 +50,8 @@ func UDPHandler(s *stack.Stack, device *net.Interface, udpAddr string) func(id s log.Debugf("[TUN-UDP] Error: can not create endpoint: %v", tErr) return } - ctx := context.Background() - c, err := forwardChain.Node().Client.Dial(context.Background(), forwardChain.Node().Addr) + c, err := forwardChain.Node().Client.Dial(ctx, forwardChain.Node().Addr) if err != nil { log.Debugf("[TUN-TCP] Error: failed to dial remote conn: %v", err) return @@ -75,9 +74,9 @@ func UDPHandler(s *stack.Stack, device *net.Interface, udpAddr string) func(id s go func() { i := config.LPool.Get().([]byte)[:] defer config.LPool.Put(i[:]) - written, err2 := io.CopyBuffer(remote, conn, i) + written, err := io.CopyBuffer(remote, conn, i) log.Debugf("[TUN-UDP] Debug: write length %d data to remote", written) - errChan <- err2 + errChan <- err }() go func() { i := config.LPool.Get().([]byte)[:]