From e7e9254630bd0557363a13dc8e5dfe3a9754a3c8 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: Tue, 23 Jun 2026 19:37:21 +0800 Subject: [PATCH] TUN inbound: Avoid panic on nil RemoteAddr due to quickly closed connection (#6365) Fixes https://github.com/XTLS/Xray-core/issues/6364#issuecomment-4778262075 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- proxy/tun/handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/proxy/tun/handler.go b/proxy/tun/handler.go index d552eca53..732468f76 100644 --- a/proxy/tun/handler.go +++ b/proxy/tun/handler.go @@ -143,7 +143,14 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) { defer cancel() ctx = c.ContextWithID(ctx, session.NewID()) - source := net.DestinationFromAddr(conn.RemoteAddr()) + // if the connection is already closed, conn.RemoteAddr() will be nil + // due to gvisor weird behavior + remote := conn.RemoteAddr() + if remote == nil { + errors.LogInfo(t.ctx, "dropped quickly closed connection") + return + } + source := net.DestinationFromAddr(remote) inbound := session.Inbound{ Name: "tun", Tag: t.tag,