From 50fef8e2016f7c755d937d47f33bfb51e628a371 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 10 May 2023 16:03:28 +0800 Subject: [PATCH] fix: sing inbound should check needAdditionReadDeadline on udp too --- common/net/sing.go | 2 +- listener/sing/sing.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/net/sing.go b/common/net/sing.go index 7eb92f03..aa6f6917 100644 --- a/common/net/sing.go +++ b/common/net/sing.go @@ -23,7 +23,7 @@ func NewDeadlineConn(conn net.Conn) ExtendedConn { return deadline.NewFallbackConn(conn) } -func NewDeadlinePacketConn(pc net.PacketConn) net.PacketConn { +func NewDeadlinePacketConn(pc net.PacketConn) network.NetPacketConn { return deadline.NewFallbackPacketConn(bufio.NewPacketConn(pc)) } diff --git a/listener/sing/sing.go b/listener/sing/sing.go index 2ccdfe2d..4a86dc82 100644 --- a/listener/sing/sing.go +++ b/listener/sing/sing.go @@ -18,6 +18,7 @@ import ( mux "github.com/sagernet/sing-mux" vmess "github.com/sagernet/sing-vmess" "github.com/sagernet/sing/common/buf" + "github.com/sagernet/sing/common/bufio" "github.com/sagernet/sing/common/bufio/deadline" E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" @@ -104,6 +105,9 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network. additions = slices.Clone(additions) additions = append(additions, ctxAdditions...) } + if deadline.NeedAdditionalReadDeadline(conn) { + conn = N.NewDeadlinePacketConn(bufio.NewNetPacketConn(conn)) // conn from sing should check NeedAdditionalReadDeadline + } defer func() { _ = conn.Close() }() mutex := sync.Mutex{} conn2 := conn // a new interface to set nil in defer