Repository navigation
webcore: clone() of a Bun.file(path) body does no filesystem I/O and never writes the shared Store #43916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webcore: clone() of a Bun.file(path) body does no filesystem I/O and never writes the shared Store #43916
Changes from all commits
ed508c3
329467d
56ebe62
e053b72
9efefb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1571,9 +1571,8 @@ impl Value { | |
| } | ||
|
|
||
| if let Value::Blob(b) = self { | ||
| if b.store() | ||
| .is_some_and(|store| !blob::store_reads_repeatably(store)) | ||
| { | ||
| // No stat here: a path is duped as it is, so a FIFO given by path is not detected. | ||
| if b.store().is_some_and(blob::store_is_fd) { | ||
|
Comment on lines
+1574
to
+1575
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1545,1605p' src/runtime/webcore/Body.rs
printf '\n--- from_blob_copy_ref ---\n'
sed -n '500,595p' src/runtime/webcore/ReadableStream.rs
printf '\n--- relevant Body helpers ---\n'
sed -n '780,825p' src/runtime/webcore/Body.rs
printf '\n--- PR change ---\n'
git diff e196cd6abba60ae2c3c42eb29ffa6fdc82e37a8a e053b728f6d055983a9c0eb96ff3bb28a3f2d8bb -- src/runtime/webcore/Body.rsRepository: oven-sh/bun Length of output: 8974 🏁 Script executed: rg -n -C 8 'from_readable_stream_without_lock_check|from_js_direct\(|fn tee|pub.*tee|from_blob_copy_ref' src/runtime/webcore/Body.rs src/runtime/webcore/ReadableStream.rs
rg -n -C 6 'size\.get\(\)|recommended_chunk_size' src/runtime/webcore/Body.rs src/runtime/webcore/Blob.rs src/runtime/webcore/ReadableStream.rsRepository: oven-sh/bun Length of output: 41783 🏁 Script executed: rg -n -C 12 'clone_body_value_via_cached_stream|clone_with_readable_stream|pub.*clone|Response.*clone|clone\(' src/runtime/webcore --glob '*.rs' | head -n 260Repository: oven-sh/bun Length of output: 19897 🏁 Script executed: rg -n -C 18 'clone_body_value_via_cached_stream' srcRepository: oven-sh/bun Length of output: 14940 Tee every file-backed Blob from one lazy reader.
Use Suggested fix- // No stat here: a path is duped as it is, so a FIFO given by path is not detected.
- if b.store().is_some_and(blob::store_is_fd) {
- // A pipe or other fd yields its bytes once: read it as one
- // stream and tee that.
- self.to_readable_stream(cx)?;
+ if b
+ .store()
+ .is_some_and(|store| matches!(&store.data, blob::store::Data::File(_)))
+ {
+ // A file-backed body can yield its bytes once: read it as one
+ // lazy stream and tee that.
+ let stream = ReadableStream::from_blob_copy_ref(cx, b, b.size.get())?;
+ *self = Value::from_readable_stream_without_lock_check(
+ ReadableStream::from_js_direct(stream).unwrap(),
+ cx.global(),
+ );
return self.tee(cx, None);
}🤖 Prompt for AI Agents |
||
| // A pipe or other fd yields its bytes once: read it as one | ||
| // stream and tee that. | ||
| self.to_readable_stream(cx)?; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.