fix: sing inbound should check needAdditionReadDeadline on udp too

This commit is contained in:
gVisor bot 2023-05-10 16:03:28 +08:00
parent ec4508255d
commit 50fef8e201
2 changed files with 5 additions and 1 deletions

View File

@ -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))
}

View File

@ -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