-
-
Notifications
You must be signed in to change notification settings - Fork 666
fix: fix wrong stream canceled up after cloning (v7) #4415
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
Changes from all commits
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 |
---|---|---|
|
@@ -297,3 +297,30 @@ test('clone body garbage collection', async () => { | |
const cloneBody = ref.deref() | ||
assert.equal(cloneBody, undefined, 'clone body was not garbage collected') | ||
}) | ||
|
||
test('clone body garbage collection should not affect original res', async () => { | ||
let ref | ||
|
||
const doFetch = async () => { | ||
const res = new Response('hello world') | ||
|
||
// Clone res and consume its body | ||
const clone = res.clone() | ||
await clone.text() | ||
ref = new WeakRef(clone) | ||
|
||
return res | ||
} | ||
|
||
const res = await doFetch() | ||
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.
|
||
|
||
// wait for garbage collection | ||
while (true) { | ||
await setImmediate() | ||
global.gc() | ||
if (!ref.deref()) break | ||
} | ||
Comment on lines
+317
to
+322
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. When the clone is garbage collected, the original res body stream should not be canceled |
||
|
||
await setImmediate() | ||
assert.doesNotThrow(() => res.clone(), 'Body has already been consumed') | ||
}) | ||
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. This fails on
|
Uh oh!
There was an error while loading. Please reload this page.