Skip to content

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Oct 7, 2025

Fixes #5175

@anonrig anonrig requested review from a team as code owners October 7, 2025 18:47
@anonrig anonrig requested a review from jasnell October 7, 2025 19:22
@jasnell
Copy link
Collaborator

jasnell commented Oct 7, 2025

This is looking at the issue from the wrong side.. the problem is really in AllReader::loop in standard.c++... it's detaching the underlying ArrayBuffer which breaks the other branch since they're sharing a reference to the same object.

The correct fix is:

diff --git a/src/workerd/api/streams/standard.c++ b/src/workerd/api/streams/standard.c++
index df5adf3f7..1b476b077 100644
--- a/src/workerd/api/streams/standard.c++
+++ b/src/workerd/api/streams/standard.c++
@@ -2735,14 +2735,13 @@ class AllReader {
           }
 
           jsg::BufferSource bufferSource(js, handle);
-          jsg::BackingStore backing = bufferSource.detach(js);
 
-          if (backing.size() == 0) {
+          if (bufferSource.size() == 0) {
             // Weird but allowed, we'll skip it.
             return loop(js);
           }
 
-          if ((runningTotal + backing.size()) > limit) {
+          if ((runningTotal + bufferSource.size()) > limit) {
             auto error = js.v8TypeError("Memory limit exceeded before EOF.");
             auto rs = kj::mv(readable);
             state.template init<StreamStates::Errored>(js.v8Ref(error));
@@ -2750,8 +2749,8 @@ class AllReader {
                 js, [&](jsg::Lock& js) { return loop(js); });
           }
 
-          runningTotal += backing.size();
-          parts.add(jsg::BufferSource(js, kj::mv(backing)));
+          runningTotal += bufferSource.size();
+          parts.add(bufferSource.copy(js));
           return loop(js);
         };
@anonrig anonrig force-pushed the yagiz/fix-request-clone-bug branch from b03ef6a to 34d3033 Compare October 7, 2025 20:06
@anonrig
Copy link
Member Author

anonrig commented Oct 7, 2025

thanks @jasnell - duh! you're right.

@anonrig anonrig enabled auto-merge (rebase) October 7, 2025 20:08
@anonrig anonrig merged commit efd3aa4 into main Oct 7, 2025
21 checks passed
@anonrig anonrig deleted the yagiz/fix-request-clone-bug branch October 7, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants