fix: sing inbound should check needAdditionReadDeadline on udp too

This commit is contained in:
wwqgtxx 2023-05-10 16:03:28 +08:00
parent 15a8d7c473
commit 3b291d3fbf
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