fix: Response.clone() no longer locks body when body was accessed before clone#25484
Conversation
…ore clone When `response.body` was accessed before calling `response.clone()`, the original response's body would become locked after cloning. This happened because: 1. When the cloned response was wrapped with `toJS()`, `checkBodyStreamRef` was called which moved the stream from `Locked.readable` to `js.gc.stream` and cleared `Locked.readable` 2. The subsequent code tried to get the stream from `Locked.readable`, which was now empty, so the body cache update was skipped 3. The JavaScript-level body property cache still held the old locked stream The fix updates the cache update logic to: 1. For the cloned response: use `js.gc.stream.get()` instead of `Locked.readable.get()` since `toJS()` already moved the stream 2. For the original response: use `Locked.readable.get()` which still holds the teed stream since `checkBodyStreamRef` hasn't been called yet This also applies the same fix to Request.clone(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Updated 1:26 PM PT - Dec 15th, 2025
@Jarred-Sumner, your commit dccdf82 is building: |
WalkthroughThe PR refactors cloning logic in Request and Response by updating how body caches are synchronized during clone operations. It replaces direct stream reuse with retrieving teed streams via Changes
Possibly related PRs
Suggested reviewers
Pre-merge checks✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (6)test/**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)
Files:
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}📄 CodeRabbit inference engine (test/CLAUDE.md)
Files:
test/**/*.test.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.{cpp,zig}📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Files:
src/**/*.zig📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Files:
**/*.zig📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)
Files:
🧠 Learnings (16)📚 Learning: 2025-10-19T04:55:33.099ZApplied to files:
📚 Learning: 2025-11-24T18:35:50.422ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:35:08.612ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-12-02T05:59:51.485ZApplied to files:
📚 Learning: 2025-09-30T22:53:19.887ZApplied to files:
📚 Learning: 2025-11-24T18:35:50.422ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-10-19T02:44:46.354ZApplied to files:
📚 Learning: 2025-08-31T09:08:12.104ZApplied to files:
📚 Learning: 2025-12-02T05:59:51.485ZApplied to files:
📚 Learning: 2025-09-05T18:45:29.200ZApplied to files:
📚 Learning: 2025-12-02T05:59:51.485ZApplied to files:
📚 Learning: 2025-11-24T18:35:39.205ZApplied to files:
📚 Learning: 2025-10-19T03:01:29.084ZApplied to files:
🧬 Code graph analysis (2)test/js/web/request/request.test.ts (1)
test/js/web/fetch/response.test.ts (1)
🔇 Additional comments (8)
Comment |
Summary
Response.clone()would lock the original response's body whenresponse.bodywas accessed before cloningRequest.clone()Root Cause
When
response.bodywas accessed before callingresponse.clone(), the original response's body would become locked after cloning. This happened because:toJS(),checkBodyStreamRef()was called which moved the stream fromLocked.readabletojs.gc.streamand clearedLocked.readableLocked.readable, which was now empty, so the body cache update was skippedFix
Updated the cache update logic to:
js.gc.stream.get()instead ofLocked.readable.get()sincetoJS()already moved the streamLocked.readable.get()which still holds the teed stream sincecheckBodyStreamRefhasn't been called yetReproduction
Test plan
Response.clone()intest/js/web/fetch/response.test.tsRequest.clone()intest/js/web/request/request.test.ts🤖 Generated with Claude Code