fix(io): preserve ownership of read_some chunks#514
Merged
Conversation
Collaborator
|
lgtm. Initially I was thinking of letting |
Guest0x0
approved these changes
Jul 23, 2026
Guest0x0
force-pushed
the
fix/read-buffer
branch
from
July 23, 2026 10:11
b1d4204 to
4f6927f
Compare
Collaborator
|
Thanks for your contribution! |
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.
Reader::read_somecould return aBytesvalue backed by its reusable internal read buffer. When a returned view covered the entire buffer,BytesView::to_owned()reused the backingBytesinstead of copying it. A later read then overwrote data that had already been returned to the caller.This is observable outside HTTP as a general
Readerownership bug. On the JavaScript backend it corrupts streamed fetch request bodies:JsReadableStream::new_pipeenqueues a chunk, the next pipe read reuses the same 1024-byte buffer, and fetch later observes the overwritten bytes.Problem
Before writing to @http.Client, the serialized UTF-8 body was captured. A local Node HTTP server captured the exact bytes received on the wire.
expected bytes: 2654
received bytes: 2654
chunks: 1024 + 1024 + 606
expected SHA-256: 2cafae89bff675c6fb8e6a49e904356c598f52f0743de9506578c5a9d2e23368
received SHA-256: dd4fee7cc2820e53922b5304b83d61984638f97568a0b6f50072776f3411a8d6
first differing offset: 0
server-side JSON.parse: failed
The received stream was not simply truncated. Its layout showed buffer reuse:
received[0..1630] == expected[1024..2654]
received[1630..2654] == expected[1630..2654]
At chunk boundaries this was:
received chunk 1 = expected chunk 2
received chunk 2 = expected final 606 bytes + stale 418-byte tail
received chunk 3 = expected final 606 bytes