Repository navigation
fix: send Content-Length on upload requests instead of chunked - #143
Merged
Merged
Conversation
The upload body goes through an io.TeeReader, which hides its length, so Go switched to Transfer-Encoding: chunked. Servers with hand-written HTTP parsers that never chunk-decode (librespeed-rs) read the raw stream in fixed-size blocks; once the finite payload is sent the stream does not end (the client keeps the connection open) and the block fill stalls, so the server never answers. The request then never completes and the upload stops after a single payload: 1 MiB / 15 s default duration = 0.55 Mbps (#122). Set an explicit Content-Length for the fixed-size payload, which every server handles. The --no-preallocate stream from crypto/rand stays chunked, which is safe: it never ends, so a raw-block reader keeps making progress. Regression test runs Upload against a raw TCP server replicating the librespeed-rs body handling and asserts the request carries Content-Length and the upload consumes more than one payload. It fails without the fix (server sees Content-Length 0).
This was referenced Aug 17, 2026
maddie
added a commit
that referenced
this pull request
Aug 17, 2026
#144) #143 set Content-Length to the raw --upload-size option value, but SetUploadSize scales it by 1024, so a default 1024 KiB payload went out as ContentLength=1024 with a 1 MiB body. The transport rejects the mismatch ("ContentLength=1024 with Body length 1048576"), the request fails, and the upload stalls at one payload again (1 MiB / 5 s = 1.61 Mbps). Use the generated payload's actual length instead. The regression test now uses the CLI's real unit semantics (1024 KiB -> 1 MiB payload) and asserts the server sees Content-Length 1048576; the previous test passed by accident because it fed an already-scaled uploadSize in.
Closed
4 tasks done
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
Uploadwraps the payload in anio.TeeReaderfor counting, which hides its length fromhttp.NewRequest, so Go sendsTransfer-Encoding: chunked. Servers with hand-written HTTP parsers that never chunk-decode — librespeed/speedtest-rust — read the raw stream in fixed-size blocks instead. Once the finite payload is sent the stream does not end (the client keeps the connection open), the block fill stalls, and the server never answers. The request never completes, no replacement request is spawned, and the upload stops after a single payload: 1 MiB / 15 s default duration = 0.55 Mbps, exactly the value in #122.Reproduced locally against a server replicating the librespeed-rs body handling: current master reports
Upload rate: 0.55 Mbps; the server log showsCHUNKED: read 1048837 raw bytes, then EOF/blocked— 1024×1024 payload + 261 bytes of chunk framing, not a multiple of the 1024-byte read block, so the final block never fills.Fix
Set
uploadReq.ContentLength = int64(uploadSize)for the fixed-size payload (preallocation mode). Content-Length is the standard, universally supported form:--no-preallocatekeeps itscrypto/randstream and stays chunked, which is safe: an endless stream keeps a raw-block reader making progress (the pre-v1.0.13 behaviour).Verification
TestUploadSendsContentLength: runs Upload against a raw TCP server replicating librespeed-rs body semantics, asserts the request carriesContent-Lengthand more than one payload is consumed. Fails without the fix (server saw Content-Length 0).go build/go vet/go test ./.../go test -race ./...all pass.Closes #122 (pending confirmation from the reporter that the rust backend now behaves).