From 9b2841f33dc76d948427eb61c54377b03bd73ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 3 Aug 2022 10:24:24 +0800 Subject: [PATCH] Close endpoint only if err return --- gvisor.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gvisor.go b/gvisor.go index c5b8092..46b1de3 100644 --- a/gvisor.go +++ b/gvisor.go @@ -127,8 +127,10 @@ func (t *GVisorTun) Start() error { var metadata M.Metadata metadata.Source = M.SocksaddrFromNet(lAddr) metadata.Destination = M.SocksaddrFromNet(rAddr) - t.handler.NewConnection(t.ctx, &gTCPConn{tcpConn}, metadata) - endpoint.Abort() + hErr := t.handler.NewConnection(t.ctx, &gTCPConn{tcpConn}, metadata) + if hErr != nil { + endpoint.Abort() + } }() }).HandlePacket) @@ -150,8 +152,10 @@ func (t *GVisorTun) Start() error { var metadata M.Metadata metadata.Source = M.SocksaddrFromNet(lAddr) metadata.Destination = M.SocksaddrFromNet(rAddr) - t.handler.NewPacketConnection(ContextWithNeedTimeout(t.ctx, true), bufio.NewPacketConn(&bufio.UnbindPacketConn{ExtendedConn: bufio.NewExtendedConn(&gUDPConn{udpConn}), Addr: M.SocksaddrFromNet(rAddr)}), metadata) - endpoint.Abort() + hErr := t.handler.NewPacketConnection(ContextWithNeedTimeout(t.ctx, true), bufio.NewPacketConn(&bufio.UnbindPacketConn{ExtendedConn: bufio.NewExtendedConn(&gUDPConn{udpConn}), Addr: M.SocksaddrFromNet(rAddr)}), metadata) + if hErr != nil { + endpoint.Abort() + } }() }).HandlePacket) } else {