[PR #3362] fix(xray): pin the server endpoint to the pre-resolved address #3262

Open
opened 2026-11-07 17:58:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3362
Author: @HEIZ2303
Created: 10/31/2026
Status: 🔄 Open

Base: dev ← Head: fix/xray-pin-server-address


📝 Commits (1)

  • e633223 fix(xray): pin the server endpoint to the pre-resolved address

📊 Changes

1 file changed (+75 additions, -2 deletions)

View changed files

📝 client/core/protocols/xrayProtocol.cpp (+75 -2)

📄 Description

Problem

On desktop, an XRay config whose server is a host name (vless://…@vpn.example.com:443?…&sni=vpn.example.com, typical for imported native configs) connects but passes no traffic.

XrayProtocol already resolves the host before the tunnel is set up (m_remoteAddress) and uses that address for routes, but the XRay config still contains the host name in outbounds[*].settings.vnext[*].address. XRay resolves it again for every new outbound connection, after the system DNS has been switched to the tunnel's resolvers. The query goes into the tunnel, which needs a connection to the server to answer it: a deadlock.

Observed on Linux (Linux Mint 22.3, 5.0.3.0): right after connecting, tun2socks queues hundreds of connections to the local XRay inbound while XRay holds only the few server connections opened before the DNS switch; the logs show the server host queried every 5 s without an answer. On disconnect the resolver is restored, all queued lookups succeed at once and XRay opens a burst of connections.

#3165 fixes the same deadlock on macOS (#3132); the root cause is not macOS-specific.

Fix

Before starting XRay, start() builds a runtime copy of the config in which every outbound endpoint (vnext and servers) whose address equals the server host name points at the pre-resolved address. If such an outbound uses TLS or REALITY without an explicit serverName, the host name is written there, so the SNI (and the transport host derived from it) is not replaced by the IP. The stored profile is not modified; configs that already use an IP are left as they are.

Validation

  • Built on dev with -DAMNEZIA_BUILD_TESTS=ON, ctest passes.
  • An earlier revision of the same change on top of 5.0.3.0 (same address pinning; it also filled the transport host fields and logged the addresses), installed on Linux Mint 22.3: a VLESS + REALITY + Vision profile with a domain endpoint now carries traffic; the log shows one pinned outbound, XRay's server connections go out over the uplink interface and their number matches the tunneled connections.
  • Not tested on Windows and macOS.

Note: on a Linux machine with Docker the connection also needs the default-gateway fix from #3231 / #3170; without it the service does not bind XRay's sockets to the uplink interface and the traffic loops into tun2 regardless of this change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amnezia-client/pull/3362 **Author:** [@HEIZ2303](https://github.com/HEIZ2303) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/xray-pin-server-address` --- ### 📝 Commits (1) - [`e633223`](https://github.com/amnezia-vpn/amnezia-client/commit/e633223abef8a521b679802cd8b24716c330c311) fix(xray): pin the server endpoint to the pre-resolved address ### 📊 Changes **1 file changed** (+75 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `client/core/protocols/xrayProtocol.cpp` (+75 -2) </details> ### 📄 Description ## Problem On desktop, an XRay config whose server is a host name (`vless://…@vpn.example.com:443?…&sni=vpn.example.com`, typical for imported native configs) connects but passes no traffic. `XrayProtocol` already resolves the host before the tunnel is set up (`m_remoteAddress`) and uses that address for routes, but the XRay config still contains the host name in `outbounds[*].settings.vnext[*].address`. XRay resolves it again for every new outbound connection, after the system DNS has been switched to the tunnel's resolvers. The query goes into the tunnel, which needs a connection to the server to answer it: a deadlock. Observed on Linux (Linux Mint 22.3, 5.0.3.0): right after connecting, tun2socks queues hundreds of connections to the local XRay inbound while XRay holds only the few server connections opened before the DNS switch; the logs show the server host queried every 5 s without an answer. On disconnect the resolver is restored, all queued lookups succeed at once and XRay opens a burst of connections. #3165 fixes the same deadlock on macOS (#3132); the root cause is not macOS-specific. ## Fix Before starting XRay, `start()` builds a runtime copy of the config in which every outbound endpoint (`vnext` and `servers`) whose address equals the server host name points at the pre-resolved address. If such an outbound uses TLS or REALITY without an explicit `serverName`, the host name is written there, so the SNI (and the transport host derived from it) is not replaced by the IP. The stored profile is not modified; configs that already use an IP are left as they are. ## Validation - Built on `dev` with `-DAMNEZIA_BUILD_TESTS=ON`, `ctest` passes. - An earlier revision of the same change on top of 5.0.3.0 (same address pinning; it also filled the transport `host` fields and logged the addresses), installed on Linux Mint 22.3: a VLESS + REALITY + Vision profile with a domain endpoint now carries traffic; the log shows one pinned outbound, XRay's server connections go out over the uplink interface and their number matches the tunneled connections. - Not tested on Windows and macOS. Note: on a Linux machine with Docker the connection also needs the default-gateway fix from #3231 / #3170; without it the service does not bind XRay's sockets to the uplink interface and the traffic loops into `tun2` regardless of this change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3262
No description provided.