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