Skip to content

XHTTP: stream replayable HTTP/2 packets and release retired connections - #7572

Closed
wywywywycloud wants to merge 1 commit into
XTLS:mainfrom
wywywywycloud:fix/xhttp-h2-packet-body
Closed

wywywywycloud wants to merge 1 commit into
XTLS:mainfrom
wywywywycloud:fix/xhttp-h2-packet-body

Conversation

@wywywywycloud

@wywywywycloud wywywywycloud commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Related to #7568. This change targets HTTP/2 body uploads and connection retirement. It applies directly to 919d0ae and does not include #7569 or #7571.

Changes

  • Give each replay an independent cursor over the original pooled buffers. Keep the payload alive until the request and all readers release it, including asynchronous Close and partial reads.
  • Return at most 16 KiB per body read to limit growth of the HTTP/2 DATA write buffer. POST size and Content-Length stay unchanged.
  • Close idle HTTP/2 connections when XMUX retires a client. Close the last download body before checking for retirement and repeat the idle check when outstanding uploads finish.

Verification

OpenWrt 25.12.5 amd64 VM, two vCPUs, 256 MiB RAM, no swap, GOMEMLIMIT=28MiB, GOGC=30. The server was unmodified Xray v26.11.9. Each round uploaded 32 MiB plus 23 bytes times the stream index per VLESS/XHTTP packet-up stream. The receiver sent back the SHA-256 of each stream. Rounds ran in one client process with five-second pauses. Memory figures are sampled RssAnon, not total system memory.

Client Parallel streams SHA-256 matches Peak RssAnon HTTP/2 read loops at end Elapsed incl. pauses
main 919d0ae 16 48/48 51.77 MiB 6 34.94 s
This PR 16 48/48 41.20 MiB 3 38.90 s
This PR 32 96/96 66.20 MiB 3 47.20 s

Both 16-stream runs created six XMUX clients and retired three. The 32-stream baseline hit the 60 MiB available-memory guard in round one. This PR alone still came close to that guard (61.52 MiB minimum available). #7571 addresses the separate queue cost. These runs had no artificial RAM reservation.

Both retirement tests failed against main with the baseline HTTP version set to 2. They passed on this branch. For a 1,000,000-byte payload, BenchmarkPacketBody reported 1,028,331 B/op for the copy and 11,334 B/op for shared readers (100 iterations). This is an allocation benchmark, not a network speedup.

The splithttp package passed three times. Targeted tests passed ten times under the race detector, including replay after redirects, partial reads, concurrent close and retirement. Linux arm64 cross-build passed.

Combined low-memory check

The three single-commit branches (769b2fe, 3bc0585, 889c083) merged cleanly into tree 80efcd74215b16ccbac413eb811f75eb90a7b53c. With 90 MiB reserved in tmpfs and a 12 MiB available-memory stop threshold, each protocol ran six rounds of 32 concurrent streams without restarting the client between rounds.

Protocol SHA-256 matches Peak RssAnon Minimum available Elapsed incl. pauses
HTTP/1.1 192/192 21.82 MiB 20.59 MiB 103.69 s
HTTP/2 over TLS 192/192 26.82 MiB 15.51 MiB 102.99 s

A separate three-round HTTP/1.1 over TLS run passed 96/96 checks, with a 27.77 MiB peak RssAnon and 16.88 MiB minimum available. No run hit the guard, logged failed uploads or reported a server queue overflow. These are synthetic VM results. Physical ARM64 hardware was not tested.

Without the reservation the combined build passed another 192/192 HTTP/2 checks. Peak RssAnon was 27.71 MiB and minimum available memory was 78.62 MiB.

Single-stream check

For one 64 MiB HTTP/2 upload without a RAM reservation, transfer times were 3.35, 2.12 and 2.09 seconds on main and 2.25, 2.10 and 2.25 seconds with all three changes. All six digests matched. The combined median was about 6% slower in this small sample.

Codex + Astra 6.2 was used for debbugging and assisted writing the code. The chat will not be included.

Share immutable buffers across independent request readers and bound DATA reads without lowering the POST size. Close idle HTTP/2 connections after the last response body and any pending uploads have finished.
@wywywywycloud
wywywywycloud force-pushed the fix/xhttp-h2-packet-body branch from b023a3f to 3bc0585 Compare December 5, 2026 00:41
@Fangliding

Copy link
Copy Markdown
Member

暂时不打算对h2做单独retry 连h1上都有点麻烦了 一般来看mux在h2里不太容易失败

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.

2 participants