From 1a9104c003707e23dc2612f23a2ef73792a97b77 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 15 May 2023 19:06:58 +0800 Subject: [PATCH] fix: UDP packet should not return io.EOF --- common/net/packet/packet_posix.go | 9 +++++---- go.mod | 2 +- go.sum | 4 ++-- tunnel/connection.go | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common/net/packet/packet_posix.go b/common/net/packet/packet_posix.go index 3c5d23a6..2861482f 100644 --- a/common/net/packet/packet_posix.go +++ b/common/net/packet/packet_posix.go @@ -3,7 +3,6 @@ package packet import ( - "io" "net" "strconv" "syscall" @@ -34,6 +33,7 @@ func (c *enhanceUDPConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, } else { put() put = nil + data = nil } if readErr == syscall.EAGAIN { return false @@ -48,9 +48,10 @@ func (c *enhanceUDPConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, addr = &net.UDPAddr{IP: ip[:], Port: from.Port, Zone: strconv.FormatInt(int64(from.ZoneId), 10)} } } - if readN == 0 { - readErr = io.EOF - } + // udp should not convert readN == 0 to io.EOF + //if readN == 0 { + // readErr = io.EOF + //} return true }) if err != nil { diff --git a/go.mod b/go.mod index 9b1e2dbd..3ecee7a1 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/mdlayher/netlink v1.7.2 github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58 github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c - github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd + github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69 github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376 github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a github.com/miekg/dns v1.1.54 diff --git a/go.sum b/go.sum index d38293a3..80d18133 100644 --- a/go.sum +++ b/go.sum @@ -98,8 +98,8 @@ github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58 h1:E/sNW9tugF github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58/go.mod h1:9nOiGX6kqV3+ZbkDKdTNzdFD726QQHPH6WDb36jUSpA= github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c h1:LpVNvlW/xE+mR8z76xJeYZlYznZXEmU4TeWeuygYdJg= github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c/go.mod h1:4uQQReKMTU7KTfOykVBe/oGJ00pl38d+BYJ99+mx26s= -github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd h1:RXdD763CbvqaJOyFLAh6xa8xg7BZTkOJ0p8fBc7kB+w= -github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd/go.mod h1:r+JnKYxqLJIkRhpT9xb3b11icXsvM6yVjCxr2Smp1Og= +github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69 h1:6mwe6TyQUqjpqu8QwRlY5xR5VjENzXtM3LVRhjq00nw= +github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69/go.mod h1:r+JnKYxqLJIkRhpT9xb3b11icXsvM6yVjCxr2Smp1Og= github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376 h1:zKNsbFQyleMFAP7NJYRew9sEMJuniuODH3V0FdWnEtk= github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376/go.mod h1:BMfG00enVf90/CzcdX9PK3Dymgl7BZqHXJfexEyB7Cc= github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a h1:cWKym33Qvl6HA3hj4/YuYD8hHyqQPb47wT5cJRAPgco= diff --git a/tunnel/connection.go b/tunnel/connection.go index 73c3e499..321c7d06 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -55,7 +55,9 @@ func handleUDPToLocal(packet C.UDPPacket, pc N.EnhancePacketConn, key string, oA } _, err = packet.WriteBack(data, fromUDPAddr) - put() + if put != nil { + put() + } if err != nil { return }