From 739a2dcd84751599bd005c665eb20ac61af53ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Mon, 19 Oct 2026 17:48:37 +0000 Subject: [PATCH] Initialize timer at the beginning --- proxy/socks/temp_udp_listen.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proxy/socks/temp_udp_listen.go b/proxy/socks/temp_udp_listen.go index 5e0dab03d..bbc078dcb 100644 --- a/proxy/socks/temp_udp_listen.go +++ b/proxy/socks/temp_udp_listen.go @@ -2,10 +2,10 @@ package socks import ( "context" - "net" "sync/atomic" "time" + "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/signal" ) @@ -14,6 +14,9 @@ func NewTempUDPConn(udpConn net.PacketConn, tcpConn net.Conn, expectedRemote *ne PacketConn: udpConn, AssociatedTCPConn: tcpConn, } + t.Timer = signal.CancelAfterInactivity(context.Background(), func() { + t.Close() + }, net.ConnIdleTimeout) t.ExpectedRemote.Store(expectedRemote) return t } @@ -60,9 +63,7 @@ func (c *TempUDPConn) RemoteAddr() net.Addr { } func (c *TempUDPConn) SetTimeout(d time.Duration) { - c.Timer = signal.CancelAfterInactivity(context.Background(), func() { - c.Close() - }, d) + c.Timer.SetTimeout(d) } func (c *TempUDPConn) Close() error {