XTLS/Xray-core · error

loopback connection detected

Error message

loopback connection detected

What it means

Loopback guard in the TCP worker's connection callback: an incoming connection's original destination (via SO_ORIGINAL_DST or local addr) points at this same inbound (same port on a wildcard address, or the hub's own address). Accepting it would create an infinite proxy-to-self loop, so the connection is cancelled, closed, and the error logged.

Solutions

  1. Change the outbound used by clients to a different destination than this inbound
  2. Adjust routing so traffic from this inbound is not routed back to itself
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at app/proxyman/inbound/worker.go:96 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/a12d452e352bb1e0. Report an issue: GitHub.

Appendix: source

Thrown at app/proxyman/inbound/worker.go:96

			dest = net.DestinationFromAddr(conn.LocalAddr())
		}

		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
		}
	}
	ctx = session.ContextWithOutbounds(ctx, outbounds)

	if w.uplinkCounter != nil || w.downlinkCounter != nil {
		conn = &stat.CounterConnection{
			Connection:   conn,
			ReadCounter:  w.uplinkCounter,
			WriteCounter: w.downlinkCounter,
		}
	}
	ctx = session.ContextWithInbound(ctx, &session.Inbound{
		Source:  net.DestinationFromAddr(conn.RemoteAddr()),
		Local:   net.DestinationFromAddr(conn.LocalAddr()),
		Gateway: net.TCPDestination(w.address, w.port),

View on GitHub (pinned to 7d214f8b09)