From 78a2dbd9d848fd7acc87be24623d506b08d20fc0 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 16 Dec 2022 22:15:44 +0800 Subject: [PATCH] chore: better safeConnClose --- adapter/outbound/http.go | 4 ++-- adapter/outbound/shadowsocks.go | 4 ++-- adapter/outbound/shadowsocksr.go | 4 ++-- adapter/outbound/snell.go | 4 ++-- adapter/outbound/socks5.go | 8 ++++---- adapter/outbound/trojan.go | 4 ++-- adapter/outbound/vless.go | 4 ++-- adapter/outbound/vmess.go | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/adapter/outbound/http.go b/adapter/outbound/http.go index bdcf5c9f..c5c06208 100644 --- a/adapter/outbound/http.go +++ b/adapter/outbound/http.go @@ -67,9 +67,9 @@ func (h *Http) DialContext(ctx context.Context, metadata *C.Metadata, opts ...di } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = h.StreamConn(c, metadata) if err != nil { diff --git a/adapter/outbound/shadowsocks.go b/adapter/outbound/shadowsocks.go index 263284b0..99f402cb 100644 --- a/adapter/outbound/shadowsocks.go +++ b/adapter/outbound/shadowsocks.go @@ -90,9 +90,9 @@ func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata, op } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = ss.StreamConn(c, metadata) return NewConn(c, ss), err diff --git a/adapter/outbound/shadowsocksr.go b/adapter/outbound/shadowsocksr.go index c4112e6e..93c16401 100644 --- a/adapter/outbound/shadowsocksr.go +++ b/adapter/outbound/shadowsocksr.go @@ -66,9 +66,9 @@ func (ssr *ShadowSocksR) DialContext(ctx context.Context, metadata *C.Metadata, } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = ssr.StreamConn(c, metadata) return NewConn(c, ssr), err diff --git a/adapter/outbound/snell.go b/adapter/outbound/snell.go index f2bc6116..c4fe77ff 100644 --- a/adapter/outbound/snell.go +++ b/adapter/outbound/snell.go @@ -84,9 +84,9 @@ func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = s.StreamConn(c, metadata) return NewConn(c, s), err diff --git a/adapter/outbound/socks5.go b/adapter/outbound/socks5.go index fe3b9bdc..62de1621 100644 --- a/adapter/outbound/socks5.go +++ b/adapter/outbound/socks5.go @@ -71,9 +71,9 @@ func (ss *Socks5) DialContext(ctx context.Context, metadata *C.Metadata, opts .. } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = ss.StreamConn(c, metadata) if err != nil { @@ -99,9 +99,9 @@ func (ss *Socks5) ListenPacketContext(ctx context.Context, metadata *C.Metadata, c = cc } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) tcpKeepAlive(c) var user *socks5.User diff --git a/adapter/outbound/trojan.go b/adapter/outbound/trojan.go index 9d3dcd4c..18d61c4a 100644 --- a/adapter/outbound/trojan.go +++ b/adapter/outbound/trojan.go @@ -127,9 +127,9 @@ func (t *Trojan) DialContext(ctx context.Context, metadata *C.Metadata, opts ... } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = t.StreamConn(c, metadata) if err != nil { diff --git a/adapter/outbound/vless.go b/adapter/outbound/vless.go index f1e62829..aaf60cb9 100644 --- a/adapter/outbound/vless.go +++ b/adapter/outbound/vless.go @@ -225,9 +225,9 @@ func (v *Vless) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.StreamConn(c, metadata) return NewConn(c, v), err diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 65d3073b..9573cd08 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -238,9 +238,9 @@ func (v *Vmess) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.StreamConn(c, metadata) return NewConn(c, v), err