XHTTP: define Request.GetBody for packet-up so h2 can replay after GOAWAY - #6632
Open
FunLay123 wants to merge 2 commits into
Open
XHTTP: define Request.GetBody for packet-up so h2 can replay after GOAWAY#6632FunLay123 wants to merge 2 commits into
FunLay123 wants to merge 2 commits into
Conversation
Member
|
这个重试看起来还行 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
packet-upmode every chunk is sent as a separate POST carrying a sequencenumber.
FillPacketRequestassignsrequest.Bodyby hand, after the requestwas created with a nil body, so
Request.GetBodyis never populated.When the peer sends GOAWAY while a request body is being written,
golang.org/x/net/http2cannot replay the request and gives up with:For
packet-upthis is not a retriable loss of bytes. Thatseqneverarrives, and the server's reassembly queue waits for it forever — it matches
nextSeqexactly and never skips (upload_queue.go) — so the session is torndown.
dialer.gointerrupts the upload pipe on anyPostPacketerror, whichkills the uplink outright.
Fix
Copy the payload into a plain slice once, release the pooled buffers
immediately, and serve both
BodyandGetBodyfrom that copy. Theelsebranch of the same function already did exactly this copy, so it is hoisted and
shared instead of duplicated.
Duplicate
seqvalues produced by a replay are harmless:uploadQueuesilently drops any packet whose
Seqis belownextSeq.Side effect: this also closes a buffer-pool leak.
io.NopClosersuppressedMultiBufferContainer.Close(), so when a request was aborted mid-write theunread buffers were never returned to the pool. Release is now explicit and
unconditional.
Evidence
Measured against Timeweb CDN, which closes
each HTTP/2 connection after ~200 requests.
A minimal probe reproducing the pre-patch code path (
Bodyassigned by hand,GetBodyleft nil), 8 concurrent requests, 400 KB bodies, 5 minutes, routedthrough the Xray tunnel itself:
A patched client carrying that same traffic in the same window, instrumented to
log every
GetBodycall:cannot retry, 0failed to send uploadover ~530 MBuploaded
Under test,
GetBody()returns the full payload even afterBodyhas alreadybeen read to completion, and the
splithttpsuite passes unchanged.Cost
One copy of the chunk per in-flight request, bounded by
scMaxEachPostBytes.The copy is released by GC once the request completes.
GetBodyitself is onlycalled on the retry path, so there is no cost in the normal case.