From 30e10be95d14b8381d8fa8c67394d91ade1bfd60 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: Wed, 10 Sep 2025 19:41:44 +0800 Subject: [PATCH] Fix https://github.com/XTLS/Xray-core/pull/5114#issuecomment-3273017153 (#5118) --- app/proxyman/inbound/worker.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index e5e3eeb1..42b5c3e9 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -77,25 +77,25 @@ func (w *tcpWorker) callback(conn stat.Connection) { case internet.SocketConfig_TProxy: dest = net.DestinationFromAddr(conn.LocalAddr()) } - // Check if try to connect to this inbound itself (can cause loopback) - var isLoopBack bool - if w.address == net.AnyIP || w.address == net.AnyIPv6 { - if dest.Port.Value() == w.port.Value() && IsLocal(dest.Address.IP()) { - isLoopBack = true - } - } else { - if w.hub.Addr().String() == dest.NetAddr() { - isLoopBack = true - } - } - if isLoopBack { - cancel() - conn.Close() - errors.LogError(ctx, errors.New("loopback connection detected")) - return - } if dest.IsValid() { + // Check if try to connect to this inbound itself (can cause loopback) + var isLoopBack bool + if w.address == net.AnyIP || w.address == net.AnyIPv6 { + if dest.Port.Value() == w.port.Value() && IsLocal(dest.Address.IP()) { + isLoopBack = true + } + } else { + if w.hub.Addr().String() == dest.NetAddr() { + isLoopBack = true + } + } + if isLoopBack { + cancel() + conn.Close() + errors.LogError(ctx, errors.New("loopback connection detected")) + return + } outbounds[0].Target = dest } }