Skip to content

XHTTP server: Add h2Params - #7295

Merged
RPRX merged 2 commits into
mainfrom
http2cfg
Oct 31, 2026
Merged

RPRX merged 2 commits into
mainfrom
http2cfg

Conversation

@Fangliding

Copy link
Copy Markdown
Member

#7282 (comment)
允许按自身需求调整 HTTP2 config 直接按json解析过去 core 基本不需要代码还自带自动更新
#6268 的受害者也可以自行调整参数 反正一切风险自负就行了

@RPRX

RPRX commented Oct 31, 2026

Copy link
Copy Markdown
Member

改名 h2Params 吧,另外你这只给 listener 加了,client 不需要加吗?#6268 说的是 client

还有我觉得对于 server 和 client 还是改下默认值更好,之前多次提过 Golang h2 栈也算特征,XDRIVE 和 MASQUE 可能也得上

@Fangliding

Copy link
Copy Markdown
Member Author

改名 h2Params 吧,另外你这只给 listener 加了,client 不需要加吗?#6268 说的是 client

client 还有那个 http2.transport 的迁移问题 两边不共享参数名 所以得推迟一下 6268 的需求的是 服务端宣告小窗口 客户端收到之后限制这边的读取buffer 所以是服务端参数

还有我觉得对于 server 和 client 还是改下默认值更好,之前多次提过 Golang h2 栈也算特征,XDRIVE 和 MASQUE 可能也得上

都已经直接听端口提供服务了 下面的TLS Server都是go的 HTTP层再改参数会出四不像掩耳盗铃 所以我觉得应该都默认

@RPRX

RPRX commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

然而直连主力 REALITY 若被主动探测可大概率不是 Go 所以,此外还要解决双重 post-handshake-records 问题和 8192 问题

先开放个自定义 h2Params 的口子吧,然后看看有没有人提出更合适的默认值

另外关于客户端的 #6797 ,Go 1.27.4 后 core 内尽力去掉 x/net/http2,XHTTP ALPN 改为 XDNS 的新方案 #7140 (comment)

@RPRX RPRX changed the title Allow custom HTTP2 config for listener XHTTP server: Add 好 Oct 31, 2026
@RPRX RPRX changed the title XHTTP server: Add 好 XHTTP server: Add h2params Oct 31, 2026
@RPRX RPRX changed the title XHTTP server: Add h2params XHTTP server: Add h2Params Oct 31, 2026
@RPRX
RPRX merged commit 316e07a into main Oct 31, 2026
46 checks passed
legiz-ru added a commit to legiz-ru/Prizrak-Core that referenced this pull request Nov 1, 2026
… KeepAlive

Ported from Jolymmiles/Xray-core (v26.10.28-1202, v26.11.1-1424) and
XTLS/Xray-core#7295 for the VLESS inbound's xhttp-config:

- h2-flow: the server role of the HTTP/2 flow governor, whose code was
  already here for the client. enabled turns it on per inbound;
  max-stream-receive-window and max-connection-receive-window set the
  upload windows (6 MiB by default with the governor);
  max-connection-send-window bounds what one connection's client holds
  of the server's data (4 MiB, -1 for no limit); queue-cuts (on) lets a
  download hold its rate beside other traffic (the fork's MetaCubeX#64). The
  governor sits above TLS and REALITY and shows the HTTP server a
  metacubex/tls connection as TLS, so ALPN and plaintext probes are
  answered as before.
- h2-params: the server's HTTP/2 settings (max-concurrent-streams,
  frame size, windows, header tables, ping and write timeouts). A
  receive window in h2-flow overrides it; with the governor
  max-concurrent-streams is at most 4096, the streams it tracks. Both
  blocks are checked before any listener binds.
- mux-keep-alive-secs and mux-keep-alive-bytes: a Mux.Cool server pokes
  a packet-up or stream-up downlink that has carried nothing for that
  long with a padded KeepAlive frame, which every client discards, so
  CDNs and reverse proxies do not cut it as idle. Off by default;
  stream-one is never poked. The poke loop ends with the carrier and
  its close does not wait for it.
Medium1992 added a commit to Medium1992/Xray-core-fork that referenced this pull request Nov 1, 2026
Upstream's XHTTP h2Params (XTLS#7295) took field 30 of the splithttp Config,
which the fork's muxKeepAliveSecs held. The fork's fields move to 100-102,
as in Jolymmiles/Xray-core, so upstream's next numbers stay free; a protobuf
config built against the old numbers must be regenerated, JSON configs are
unaffected.

On the server h2Params is the base HTTP/2 config: a receive window set in
h2Flow overrides it, and with the governor on its defaults fill a window
neither sets. A governed server rejects MaxConcurrentStreams above the
streams the governor tracks. h2Params is parsed before the listener binds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Medium1992 added a commit to Medium1992/xray-proxy-ros that referenced this pull request Nov 1, 2026
…iew fixes

Upstream's XHTTP h2Params (XTLS/Xray-core#7295) took field 30 of the
splithttp Config and changed the lines where the server builds its HTTP/2
config, so patches/xhttp-flow stopped applying from the first patch on and
the stable and alpha builds stopped at their patch test.

The series is rebased onto v26.10.31 as in the mux-ka fork's
v26.10.31-h2Flow: h2Params is the base of a governed server's HTTP/2
config, a window set in h2Flow overrides it, and the fork's fields take
100-102 (muxKeepAliveSecs, muxKeepAliveBytes, h2Flow). Two fixes from a
review follow: a download the server ended no longer lifts the
connection's send window, and pi forgets its last error outside pi.

Checked as Dockerfile-release applies them, on a clean v26.10.31: every
patch applies, the hooks are found, the flow job's tests and the full
splithttp, infra/conf and common/mux tests pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
legiz-ru added a commit to legiz-ru/Prizrak-Core that referenced this pull request Nov 2, 2026
… KeepAlive

Ported from Jolymmiles/Xray-core (v26.10.28-1202, v26.11.1-1424) and
XTLS/Xray-core#7295 for the VLESS inbound's xhttp-config:

- h2-flow: the server role of the HTTP/2 flow governor, whose code was
  already here for the client. enabled turns it on per inbound;
  max-stream-receive-window and max-connection-receive-window set the
  upload windows (6 MiB by default with the governor);
  max-connection-send-window bounds what one connection's client holds
  of the server's data (4 MiB, -1 for no limit); queue-cuts (on) lets a
  download hold its rate beside other traffic (the fork's MetaCubeX#64). The
  governor sits above TLS and REALITY and shows the HTTP server a
  metacubex/tls connection as TLS, so ALPN and plaintext probes are
  answered as before.
- h2-params: the server's HTTP/2 settings (max-concurrent-streams,
  frame size, windows, header tables, ping and write timeouts). A
  receive window in h2-flow overrides it; with the governor
  max-concurrent-streams is at most 4096, the streams it tracks. Both
  blocks are checked before any listener binds.
- mux-keep-alive-secs and mux-keep-alive-bytes: a Mux.Cool server pokes
  a packet-up or stream-up downlink that has carried nothing for that
  long with a padded KeepAlive frame, which every client discards, so
  CDNs and reverse proxies do not cut it as idle. Off by default;
  stream-one is never poked. The poke loop ends with the carrier and
  its close does not wait for it.
@svlavr

svlavr commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

In ListenXH, h2Params is parsed after the TCP/Unix listener has already been opened. If json.Unmarshal fails, the function returns nil, error without closing that listener.

For example, this happens with "h2Params": []. The caller receives no listener to close, so the port may remain occupied after startup fails, preventing a subsequent start on the same port within the same process.

I suggest adding _ = l.listener.Close() in transport/internet/splithttp/hub.go, before the existing return of the failed to parse HTTP2Config error. This would release the acquired resource while preserving successful startup behavior and the existing error for invalid configurations.

@Chara-Freedom

Chara-Freedom commented Nov 6, 2026 •

Copy link
Copy Markdown

h2Params 在服务端节点上的实测,供参考。

#6268 和 #7099 的数据来自手机客户端。这里是另一种场景:节点之间的隧道。一台节点作为 XHTTP 客户端(stream-one + REALITY)连接两台节点,每个被代理的连接占一条 stream,并发约 8000–11000 条。环境:8 GB 内存、无 swap 的 VM,Go 1.27.3,基于 Xray 的分支(已包含本 PR)。

修改前: 约 27 小时内 xray 被 OOM killer 杀死 4 次(anon-rss 6.4–7.2 GiB)。heap profile 中 99.6% 的采样内存来自 http2.(*clientStream).writeRequestBody,每个对象正好 524288 字节。

修改: 只在服务端 inbound 设置 "h2Params": {"MaxReadFrameSize": 16384},客户端配置不变。

两次从零启动,运行时间和负载相近(约 57700 个 goroutine):

MiB 修改前(135 s) 修改后(144 s)
RSS 3172 1867
HeapAlloc 5371 901
Sys 7473 1969
NextGC 9984 1473

进程运行 12 分 26 秒时,RSS 为 4445 和 2188 MiB。修改后目前只运行了约 12 分钟,尚未发生 OOM;修改前最长一次运行了 24 小时 36 分钟,所以现在还不能确认 OOM 已经解决。

回环测试(同一二进制,无 RTT 和丢包,1000 条 stream,5 轮交替,修改前 / 修改后):上传 1 条 stream 1747 / 1756 Mbit/s,8 条 3439 / 3816 Mbit/s,下载 1426 / 1433 Mbit/s,未见速度下降。反复打开和关闭 stream 8 轮后,RSS 为 311–336 / 139–146 MiB。

#7099 中关于特征的顾虑在逻辑上成立,但我们没有测量,也无法判断其影响有多大,所以这里不是要求修改默认值。对节点间隧道这种场景,可选的 h2Params 已经够用。


Measurements of h2Params on a server node, for reference.

The data in #6268 and #7099 comes from phone clients. This is a different case: tunnels between nodes. One node dials two others as an XHTTP client (stream-one + REALITY), with one stream per proxied connection, about 8000–11000 concurrent. Environment: 8 GB VM, no swap, Go 1.27.3, an Xray fork that includes this PR.

Before: xray was OOM-killed 4 times in about 27 hours (anon-rss 6.4–7.2 GiB). 99.6% of sampled heap came from http2.(*clientStream).writeRequestBody, each object exactly 524288 bytes.

Change: only "h2Params": {"MaxReadFrameSize": 16384} on the server inbounds; the client config is unchanged.

Two runs from a cold start, similar uptime and load (about 57700 goroutines):

MiB Before (135 s) After (144 s)
RSS 3172 1867
HeapAlloc 5371 901
Sys 7473 1969
NextGC 9984 1473

At 12 min 26 s of process uptime, RSS was 4445 and 2188 MiB. The changed setup has only run for about 12 minutes so far, with no OOM yet; the longest run before the change lasted 24 h 36 min, so it is too early to say the OOM kills are gone.

Loopback test (same binary, no RTT or loss, 1000 streams, 5 interleaved rounds, before / after): upload on 1 stream 1747 / 1756 Mbit/s, on 8 streams 3439 / 3816 Mbit/s, download 1426 / 1433 Mbit/s; no slowdown seen. After 8 rounds of opening and closing streams, RSS was 311–336 / 139–146 MiB.

The fingerprint concern in #7099 is logical, but we did not measure it and cannot say how much it matters, so this is not a request to change the default. For node-to-node tunnels like this one, the opt-in h2Params is enough.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants