Repository navigation
XHTTP: Add opt-in downlink resume - #6755
Medium1992 wants to merge 1 commit into
Conversation
The stream-down GET is the lifetime of a session, so a middlebox that resets it takes the tunneled connection with it. CDN edges do exactly that: XTLS#4846 measures an idle timer on the response stream at 10s (VK Cloud), 30s (Timeweb), 60s (Yandex Cloud) and 125.5s (Cloudflare), and none of them tells the origin. The case that bites hardest is an upload, where the download leg carries nothing, idles for the whole transfer, and is cut; the upload dies with it. scDownlinkResume lets a session outlive individual stream-down requests. The server retains what the client has not acknowledged, a reconnecting client asks to continue from the offset it actually received, and every uplink request carries that offset so retention is released as it is confirmed. scMaxDownlinkSecs additionally closes the stream before the edge does, the rotation named in XTLS#4846. Retention covers what a cut can lose, not throughput: an idling downlink holds almost nothing, while a transfer at full rate outruns any window a server can afford per session and falls back to today's behaviour. The default is 256 KiB of pooled buffers per session, returned to the pool as they are acknowledged. Because a resuming client cannot tell a cut stream from a finished one, the session outlives the tunnel for a grace period: a client that reconnects after the last bytes is answered with 204 and ends as it would on a complete response, and anything it had not received yet is still replayed. This needs no downlink wrapping format, unlike XTLS#6422: the offset travels in the placement already used for sessionID and the response body is untouched. A Range request would be the obvious alternative, but CDN edges answer those themselves and strip them before the origin, which would silently replay a stream from the wrong offset. The server therefore echoes the offset only when it arrived, so a path that drops it is indistinguishable from a server without the feature, and a stream-down request for a session that has already sent something but carries no offset is refused rather than replayed from zero. Off by default and gated on both ends like mode. If only one side enables it, the client sees the server did not acknowledge it, stops resuming and behaves as it does today. A resume the server can no longer serve is answered with 410 and the connection fails cleanly rather than retrying.
|
closed as not planed |
|
这个重连复杂度太高了 |
I tested it on a live server via a CDN and on the client side, and fixed all the bugs I could find. I'm not a programmer, but I'd like to see this feature added to the core. I created a PR to immediately demonstrate the idea and its implementation in code. Version compatibility has also been taken into account to ensure that the implementation of this feature will not affect the operation of previous kernel versions. In the current release of the kernel, the logs show the following: Every 30 or 10 seconds, depending on which CDN edge the connection passes through
|
|
一般情况下我们不接受纯ai的代码 你的pr message甚至看不出你真的读了里面列出的几个其他pr |
That was a trial implementation, and I should have started from what you suggested in #6554. I've now tried Mux.Cool over XHTTP. Un-banning alone doesn't help, I checked it through the real CDN as well: a quiet Mux connection still gets cut, and then every session on it drops at once. SessionStatusKeepAlive is handled on both sides but never sent. With the server sending it every few seconds, the cuts are gone: 13 minutes through the CDN with no stream errors, where stock gave 10 in the first minute, and no more disconnects in mobile games. The client stays stock, with concurrency: 1 (the default 8 makes parallel downloads about 3× slower). Commit: Medium1992@6aa4da56 Could Mux.Cool be allowed for XHTTP together with keepalive? The keepalive is sent only on XHTTP packet-up and stream-up, so raw, REALITY and stream-one get no extra traffic that could become a pattern. |
|
|
|
#7364 (comment) 最近大改 VLESS Multiplex,重新思考了下这个问题,由于现实中 TSPU 限制了 Chrome 指纹连接数,我认为当初 XHTTP 服务端 block 掉代理层 Mux 的做法已可以去掉,当初这样做主要是因为在 v2rayN&G 等软件中 Mux 是全局设置导致容易误开 double Mux、导致实际的连接调度、TCP 等不符合 XHTTP XMUX 的自定义预期,
@2dust 新版 Mux 改了配置位置和行为 #7364 (comment) ,GUI 需要移进每个节点内而不是全局设置,晚些时候会出分享链接 |
…ide, instead of blocking it at server side #7364 (comment) #6755 (comment) #6755 (comment)

XHTTP: Add opt-in downlink resume
Closes the failure mode measured in #4846. Off by default,
packet-up/stream-up/stream-oneunaffected when disabled.Problem
In every XHTTP mode the downlink is one stream-down GET that lives as long as
the tunneled connection. A middlebox that resets that stream takes the
connection with it.
#4846 measures what the middlebox does: an idle timer on the response
stream, reset by any body byte.
None of them tells the origin. Neither
request.Context().Done()nor a failingwrite fires, so the server cannot detect or pre-empt the cut.
Worst case is an upload: in
packet-upthe uplink never idles, but thedownlink carries proxied payload only. During an upload it carries nothing,
idles for the whole transfer, and is cut. The upload dies with it.
#6422 solved this with a keepalive byte and was closed: "introducing a frame
format just to keep alive an overly idle downlink connection is
inappropriate". #6554 closed for the same reason. This PR adds no framing
and does not touch the response body.
Mechanism
acknowledged, instead of ending the session when the GET ends.
retention up to it.
scMaxDownlinkSecs(optional) closes the stream from the client side beforethe edge does, at a randomised interval.
The reader on the client hides the boundary, so the tunneled connection sees an
uninterrupted byte stream.
Wire format
sessionID(header / query / cookie), keydownlinkResumeKey410 Gone204 No ContentRange: bytes=N-was the obvious alternative and was tested against aproduction CDN: the edge answered
206/416from its own copy and removedthe header before the origin, while an ordinary header passed through. A
stripped offset would replay a live stream from byte 0, so the offset keeps its
own header, and two rules make a hostile path safe:
indistinguishable from a server without the feature and the client stops
resuming;
no offset is refused, never served from 0.
Changes
downlink.go(new, 206)downlinkBuffer: retains unacknowledged bytes in pooledbuf.MultiBuffer, replays from an offset, survives a failing writerresumable.go(new, 207)resumableDownlink:io.ReadCloserthat reopens the request on error and continues at its offsetdownlink_test.go(new, 250)hub.goclient.goOpenDownlink, offset on the request,Rejected/Supported/Finishedon the responsedialer.goresumableDownlinkin when both ends enable it; falls back otherwiseconfig.gosessionIDonesconfig.proto,config.pb.goinfra/conf/transport_method.gobrowser_client.goConfiguration
scDownlinkResumefalsemodescMaxReplayBytesscMaxDownlinkSecsdownlinkResumeKeyX-Offset/x_offsetsessionIDGrace period after a stream ends: 30 s, matching the existing session reaper.
Memory
Retention is bounded per session and released on acknowledgement:
ceiling = concurrent sessions ×
scMaxReplayBytes256 KiB is 1/120 of what XHTTP already allows per session on the uplink
(
scMaxBufferedPosts×scMaxEachPostBytes, 30 MiB by default).Measured, 200 sessions downloading at 50 KB/s against a fast server for 100 s —
the worst case, because a pure download sends no uplink and therefore never
acknowledges:
Sessions with any uplink traffic acknowledge continuously and hold kilobytes.
Repeated bursts of ~630 short sessions leave RSS flat (43.6 → 43.2 → 42.5 MB).
Degradation
410, connection fails cleanly after one attempt, no retry stormTruncation is possible in the degradation path; corruption is not.
Testing
Bench: patched client and server with a reverse proxy modelling the edge —
resetting a response stream idle beyond a randomised threshold, and keeping the
origin request running afterwards, as a real edge does.
curl 56curl 52200at 40.06 s410, clean failure, logs stableProduction, 6.5 minutes of browsing and video through a CDN:
Known limitations
acknowledgements, so retention is released by cap alone and a transfer at
full rate outruns the window. It then fails exactly as it does today. A
periodic acknowledgement-only request would fix it but needs a request shape
the server does not read as uplink data.
mode.unpredictable case; rotation is the latency optimisation on top.
packet-upfocused.stream-upcarries its uplink as one long request,so the acknowledgement has no natural place there yet.