XHTTP: xmux.maxConnections is ineffective in Go 1.27 builds (v26.9.8+, main) — one TCP connection per session while TLS handshakes hang, leading to OOM
Integrity requirements
- I have read all the comments in the issue template and ensured that this issue meet the requirements.
- I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
- I searched issues and did not find any similar issues.
- The problem can be successfully reproduced in the latest Release
Description
简述:v26.9.8 起使用 Go 1.27 构建,x/net http2.Transport 改为包装 net/http.Transport。当 TLS 握手被阻断而挂起时,每个会话都会新建一条 TCP 连接,XMUX 的 maxConnections 实际失效,连接数和内存随会话数线性增长。使用
-tags http2legacy构建可恢复正常。与 #6644 不同,这里的额外连接与 MaxConcurrentStreams 无关。
Since v26.9.8 Xray is built with Go 1.27 (fd2ca748, "go.mod: Specify Go 1.27.x"); the v26.9.9 release binary reports go1.27.1, and the release workflow builds without extra tags. With Go 1.27, golang.org/x/net (v0.58.0 in v26.9.9, v0.59.0 on main) compiles http2/transport_wrap.go:
//go:build go1.27 && !http2legacy
// Transport wrapping a net/http.Transport.In this mode http2.Transport.RoundTrip is delegated to an internal net/http.Transport instead of x/net's own clientConnPool. The old pool deduplicated in-flight dials per address (p.dialing[addr]), so an XMUX client whose handshake hangs held exactly one socket and all further requests waited on it. The new path does not: while no HTTP/2 connection to the host is established yet, every waiting request dials its own TCP connection.
Normally this is invisible — the first handshake completes in one RTT and everything is multiplexed afterwards. But when handshakes hang (e.g. a middlebox blackholes the flow after the ClientHello — the TSPU scenario from #6376), every proxied session gets its own TCP connection. xmux.maxConnections still limits the number of XMUX clients (the debug log below shows two XMUX: creating xmuxClient lines and no removals), but not the dials underneath them.
Consequences:
maxConnections: 2/3, introduced as the anti-TSPU default (18e28390, #6376), no longer keeps the client under the ~4-connection limit — it opens hundreds or thousands of connections and keeps re-triggering the ban;- memory grows linearly with hung sessions; in a memory-limited container the process is OOM-killed, taking every other (healthy) outbound down with it.
Affected: v26.9.8, v26.9.9 and main (d562d894) — all Go 1.27 + x/net ≥ v0.58.0. v26.7.28 and earlier are built with Go 1.26 and use the legacy transport. Tested: XHTTP stream-one over TLS (h2). I did not test packet-up/stream-up or h3.
Field observation. Linux client in an LXC container with a memory limit, VLESS + XHTTP stream-one + TLS, maxConnections: 2 (effective config verified with xray run -dump, no extra). During a TSPU episode against one server (pcap on the router WAN):
- up to 2348 simultaneously open client sockets to that server; bursts of 26 SYNs within 90 ms;
- 1258 of 1261 new connections: SYN/SYN-ACK OK, the ClientHello is never ACKed, retransmitted for minutes;
- the process was OOM-killed twice, 193 s apart (
Memory cgroup out of memory: Killed process ... (xray) ... anon-rss:218772kB); the healthy HTTP/2 connections of the other outbounds were reset along with it.
Another outbound (different server) in the same process was unaffected — its handshakes complete, so the first HTTP/2 connection is established and everything multiplexes.
Related
- #6644 (closed, not merged) proposed bounding physical H2 connections for
maxConnections. It was closed after the observation that a transport only opens extra connections when the peer'sMAX_CONCURRENT_STREAMSis exceeded, which a server-side setting fixes. That analysis was done on v26.7.28 (Go 1.26) and is correct for the legacy pool. The connections here are unrelated to stream limits: the peer never completes TLS, so no SETTINGS frame is ever received and no stream limit is known. Raisinghttp2_max_concurrent_streamscannot help; the behavior appears only in Go 1.27 builds and disappears withhttp2legacy. - #6590 (closed, not planned) — a stalled dial parks its goroutine forever; considered a malicious-peer scenario. Here the stall comes from an on-path censor, not the peer (the #6376 scenario), and the impact is new: with the legacy pool it was one parked dial per XMUX client; with Go 1.27 it is one per session, unbounded, ending in OOM.
- Upstream,
transport_wrap.gohas already changed behavior in other ways, e.g. golang/go#79778 and golang/go#79642.
Workaround: build with -tags http2legacy:
CGO_ENABLED=0 go build -tags http2legacy -trimpath -buildvcs=false -ldflags "-s -w -buildid=" -o xray ./mainPossible fixes
- Build release binaries with
-tags http2legacy(verified below; smallest change). - Or bound concurrent dials per XMUX client in the XHTTP dialer itself, independently of http2 package internals. The XDRIVE transport already uses
net/http.TransportwithMaxConnsPerHost— a similar bound may work here, but I have not tested it for this path.
Reproduction Method
No Xray server is needed. A TCP server that accepts connections, reads, and never answers stands in for a server whose handshake is blackholed after the ClientHello (see Server config).
Load generator load.py — N concurrent SOCKS5 sessions spread over dur seconds:
import socket, struct, threading, time, sys
N, dur = int(sys.argv[1]), float(sys.argv[2])
def one():
try:
s = socket.create_connection(('127.0.0.1', 11080), timeout=dur)
s.sendall(b'\x05\x01\x00'); s.recv(2)
h = b'example.com'
s.sendall(b'\x05\x01\x00\x03' + bytes([len(h)]) + h + struct.pack('>H', 80))
s.recv(10); s.sendall(b'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'); s.recv(100)
except Exception: pass
for _ in range(N):
threading.Thread(target=one, daemon=True).start(); time.sleep(dur / N / 2)
time.sleep(dur)Steps:
python3 blackhole.py &
./xray run -c client.json &
python3 load.py 1500 25 &
sleep 28; ss -tn state established '( dport = :18443 )' | tail -n +2 | wc -lResults, 1500 sessions over 25 s, each run in a clean environment (ports verified free beforehand, the Xray process verified alive at measurement time):
| build | TCP connections | XMUX: creating |
RSS |
|---|---|---|---|
official v26.9.9 release (Xray-linux-64.zip, go1.27.1) |
1500 | 2 | 195 MB |
| v26.9.9 built from the tag, no tags (go1.27.0) | 1500 | 2–3 | 176–196 MB |
main d562d894, no tags |
1500 | 2 | 207 MB |
v26.9.9, -tags http2legacy |
2 | 2 | 84 MB |
v26.9.9, -tags http2legacy, static, on Alpine 3.24 |
3 | 3 | 86 MB |
With 20 sessions (the client log below): 20 connections, 2 XMUX clients.
Expected: with maxConnections: 2 the number of TCP connections stays at about 2 regardless of how many sessions are waiting, as it does with http2legacy and with Go 1.26 builds.
Client config
{
"log": {"loglevel": "debug", "dnsLog": true},
"inbounds": [{"listen": "127.0.0.1", "port": 11080, "protocol": "socks", "settings": {"udp": false}}],
"outbounds": [{
"protocol": "vless",
"settings": {"vnext": [{"address": "127.0.0.1", "port": 18443,
"users": [{"id": "b831381d-6324-4d53-ad4f-8cda48b30811", "encryption": "none"}]}]},
"streamSettings": {
"network": "xhttp", "security": "tls",
"tlsSettings": {"serverName": "example.com", "fingerprint": "chrome", "alpn": ["h2"]},
"xhttpSettings": {"host": "example.com", "path": "/x", "mode": "stream-one",
"xmux": {"maxConnections": 2, "maxConcurrency": 0, "cMaxReuseTimes": 0,
"hMaxRequestTimes": "600-900", "hMaxReusableSecs": "1800-3000", "hKeepAlivePeriod": 0}}
}
}]
}
Server config
No Xray server. blackhole.py stands in for a server whose handshake is blackholed after the ClientHello:import asyncio, sys
n=0
async def h(r,w):
global n; n+=1
try:
while await r.read(65536): pass # читаем и молчим: ClientHello принят, ServerHello не будет
except Exception: pass
async def main():
s=await asyncio.start_server(h,'127.0.0.1',18443,backlog=4096)
async def rep():
while True:
await asyncio.sleep(5); print('accepted total', n, flush=True)
asyncio.create_task(rep())
async with s: await s.serve_forever()
asyncio.run(main())
Client log
Xray 26.9.9 (Xray, Penetrates Everything.) 52a412d (go1.27.1 linux/amd64)
A unified platform for anti-censorship.
2026/09/21 14:41:57.856572 [Info] infra/conf/serial: Reading config: &{Name:client-issue.json Format:json}
2026/09/21 14:41:57.857476 [Debug] app/log: Logger started
2026/09/21 14:41:57.857483 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:11080
2026/09/21 14:41:57.857716 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:11080
2026/09/21 14:41:57.857723 [Warning] core: Xray 26.9.9 started
2026/09/21 14:41:59.860388 [Info] [3075695142] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:41:59.860404 [Info] [3075695142] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:41:59.860409 [Debug] [3075695142] transport/internet/splithttp: XMUX: creating xmuxClient because xmuxClients is empty
2026/09/21 14:41:59.860542 from tcp:127.0.0.1:40744 accepted tcp:example.com:80
2026/09/21 14:41:59.870731 [Info] [3075695142] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:41:59.870891 [Debug] [3075695142] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.008651 [Info] [1825787830] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.008666 [Info] [1825787830] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.008676 [Debug] [1825787830] transport/internet/splithttp: XMUX: creating xmuxClient because maxConnections was not hit, xmuxClients = 1
2026/09/21 14:42:00.008736 from tcp:127.0.0.1:40758 accepted tcp:example.com:80
2026/09/21 14:42:00.008753 [Info] [1825787830] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.008914 [Debug] [1825787830] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.159780 [Info] [3907544594] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.159802 [Info] [3907544594] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.159811 [Info] [3907544594] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.159901 from tcp:127.0.0.1:40768 accepted tcp:example.com:80
2026/09/21 14:42:00.160020 [Debug] [3907544594] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.309895 [Info] [653236920] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.309915 [Info] [653236920] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.309932 from tcp:127.0.0.1:40780 accepted tcp:example.com:80
2026/09/21 14:42:00.309981 [Info] [653236920] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.310165 [Debug] [653236920] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.460614 [Info] [3966413926] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.460629 [Info] [3966413926] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.460634 [Info] [3966413926] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.460712 from tcp:127.0.0.1:40796 accepted tcp:example.com:80
2026/09/21 14:42:00.460835 [Debug] [3966413926] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.610977 [Info] [1636768170] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.610997 [Info] [1636768170] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.611053 from tcp:127.0.0.1:40802 accepted tcp:example.com:80
2026/09/21 14:42:00.611074 [Info] [1636768170] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.611245 [Debug] [1636768170] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.761607 [Info] [2976687724] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.761625 [Info] [2976687724] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.761667 from tcp:127.0.0.1:45336 accepted tcp:example.com:80
2026/09/21 14:42:00.761698 [Info] [2976687724] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.761893 [Debug] [2976687724] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:00.912788 [Info] [2286947645] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:00.912824 [Info] [2286947645] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:00.912837 [Info] [2286947645] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:00.912857 from tcp:127.0.0.1:45342 accepted tcp:example.com:80
2026/09/21 14:42:00.913034 [Debug] [2286947645] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.063377 [Info] [239961799] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.063412 [Info] [239961799] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.063491 from tcp:127.0.0.1:45352 accepted tcp:example.com:80
2026/09/21 14:42:01.063499 [Info] [239961799] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.063645 [Debug] [239961799] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.214120 [Info] [1773947494] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.214151 [Info] [1773947494] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.214159 [Info] [1773947494] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.214170 from tcp:127.0.0.1:45358 accepted tcp:example.com:80
2026/09/21 14:42:01.214349 [Debug] [1773947494] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.364941 [Info] [862654821] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.365001 [Info] [862654821] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.365038 [Info] [862654821] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.365053 from tcp:127.0.0.1:45372 accepted tcp:example.com:80
2026/09/21 14:42:01.365271 [Debug] [862654821] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.516020 [Info] [1731810567] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.516054 [Info] [1731810567] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.516063 [Info] [1731810567] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.516095 from tcp:127.0.0.1:45376 accepted tcp:example.com:80
2026/09/21 14:42:01.516175 [Debug] [1731810567] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.666187 [Info] [3127971750] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.666207 [Info] [3127971750] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.666226 [Info] [3127971750] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.666239 from tcp:127.0.0.1:45384 accepted tcp:example.com:80
2026/09/21 14:42:01.666347 [Debug] [3127971750] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.816883 [Info] [1004484339] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.816899 [Info] [1004484339] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.816910 [Info] [1004484339] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.816969 from tcp:127.0.0.1:45400 accepted tcp:example.com:80
2026/09/21 14:42:01.817226 [Debug] [1004484339] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:01.967189 [Info] [2108210990] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:01.967202 [Info] [2108210990] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:01.967206 [Info] [2108210990] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:01.967274 from tcp:127.0.0.1:45404 accepted tcp:example.com:80
2026/09/21 14:42:01.967541 [Debug] [2108210990] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:02.117916 [Info] [1690246924] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:02.117933 [Info] [1690246924] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:02.117939 [Info] [1690246924] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:02.118066 from tcp:127.0.0.1:45418 accepted tcp:example.com:80
2026/09/21 14:42:02.118234 [Debug] [1690246924] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:02.268300 [Info] [489797624] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:02.268315 [Info] [489797624] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:02.268320 [Info] [489797624] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:02.268328 from tcp:127.0.0.1:45420 accepted tcp:example.com:80
2026/09/21 14:42:02.268507 [Debug] [489797624] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:02.418702 [Info] [3232071992] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:02.418718 [Info] [3232071992] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:02.418789 from tcp:127.0.0.1:45432 accepted tcp:example.com:80
2026/09/21 14:42:02.418801 [Info] [3232071992] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:02.418985 [Debug] [3232071992] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:02.569755 [Info] [2004325015] proxy/socks: TCP Connect request to tcp:example.com:80
2026/09/21 14:42:02.569807 [Info] [2004325015] app/dispatcher: default route for tcp:example.com:80
2026/09/21 14:42:02.569841 [Info] [2004325015] transport/internet/splithttp: XHTTP is dialing to tcp:127.0.0.1:18443, mode stream-one, HTTP version 2, host example.com
2026/09/21 14:42:02.569923 from tcp:127.0.0.1:45442 accepted tcp:example.com:80
2026/09/21 14:42:02.570644 [Debug] [2004325015] transport/internet: dialing to tcp:127.0.0.1:18443
2026/09/21 14:42:02.720934 [Info] [2282207934] proxy/Source: XTLS/Xray-core