From 7b8ade3ec5b1195258e0c6535b9c50ee75ba7180 Mon Sep 17 00:00:00 2001 From: Artem Lytkin <146867384+4RH1T3CT0R7@users.noreply.github.com> Date: Mon, 28 Sep 2026 00:06:19 +0300 Subject: [PATCH] TUN inbound: Only close the UDP connection that actually finished (#6814) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/XTLS/Xray-core/pull/6814#pullrequestreview-5324536423 --------- Co-authored-by: 风扇滑翔翼 --- proxy/tun/udp_fullcone.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proxy/tun/udp_fullcone.go b/proxy/tun/udp_fullcone.go index 1a1cb0843..480bb4bb7 100644 --- a/proxy/tun/udp_fullcone.go +++ b/proxy/tun/udp_fullcone.go @@ -78,11 +78,11 @@ func (u *udpConnectionHandler) HandlePacket(src net.Destination, dst net.Destina } } -func (u *udpConnectionHandler) connectionFinished(src net.Destination) { +func (u *udpConnectionHandler) connectionFinished(conn *udpConn) { u.Lock() - conn, found := u.udpConns[src] - if found { - delete(u.udpConns, src) + // Close runs twice per flow; a newer conn may already own this src. + if u.udpConns[conn.src] == conn { + delete(u.udpConns, conn.src) close(conn.egress) } u.Unlock() @@ -161,7 +161,7 @@ func (c *udpConn) Write(p []byte) (int, error) { } func (c *udpConn) Close() error { - c.handler.connectionFinished(c.src) + c.handler.connectionFinished(c) return nil }