fix(net): buffer closed ReadableStream bodies for fetch POST#3056
Merged
karlseguin merged 4 commits intoJul 26, 2026
Merged
Conversation
BodyInit.extract returned an empty body for ReadableStream request bodies, so fetch POST with duplex:half silently sent Content-Length: 0. Drain closed streams synchronously via collectBodyBytes; reject open, locked, or errored streams with TypeError instead of sending nothing. Fixes lightpanda-io#3052
|
All contributors have signed the CLA ✍️ ✅ |
JS controller.enqueue stores chunks as .js_value via enqueueValue, so collectBodyBytes must extract TypedArray/ArrayBuffer/string bytes with local scope and arena.dupe before buffering. Add multi-chunk success and open/locked reject fixtures in fetch.html.
Drop nested localScope; fetch already runs under an active Caller local. Fixes compile error where &ls (Scope) was passed where *js.Local is required.
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
Author
|
recheck |
Use existing toStringSmart to convert value to a string
Collaborator
|
Thanks. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
fetch()with aReadableStreamrequest body silently sentContent-Length: 0and an empty payload.ReadableStream.collectBodyBytesto drain a closed stream's internal queue synchronously; open, locked, or errored streams reject withTypeErrorinstead of sending nothing.controller.enqueuestores chunks as.js_valueviaenqueueValue;collectBodyBytesnow converts TypedArray/ArrayBuffer/string.js_valueentries (matchingResponse.StreamConsumer._onReadFulfilled) before buffering.BodyInit.extract.streamarm uses that helper instead of returning an empty byte slice.fetch_readablestream_body(multi-chunk success),fetch_readablestream_body_reject(open + locked streams → TypeError), plus/xhr/echo_post_bodytest-server endpoint.Approach
Implements option 2 (buffer) from the issue for the common case (stream closed synchronously in
start()with enqueued chunks), and option 1 (reject) for streams that cannot be drained synchronously. This matches the issue's expected behavior diagram and avoids silent data loss.Test plan
zig fmt --checkon changed.zigfiles — cleanTEST_FILTER="fetch_readablestream_body" make test— not run locally: V8gclient syncfailed (_bad_scmconflicts; alsoNo space left on deviceduring llvm artifact extract). Maintainer CI should exercise the HTML fixtures.make test— blocked by same V8 cache/disk issue locallyCLA
I will sign the CLA via cla-assistant-lite when prompted on this PR (first contribution to this repo).
Fixes #3052