Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

use FinalizationRegistry for cloned response body #3458

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/web/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ class Response {
// 2. Let clonedResponse be the result of cloning this’s response.
const clonedResponse = cloneResponse(this[kState])

if (hasFinalizationRegistry && this[kState].body?.stream) {
registry.register(this, new WeakRef(this[kState].body.stream))
}

// 3. Return the result of creating a Response object, given
// clonedResponse, this’s headers’s guard, and this’s relevant Realm.
return fromInnerResponse(clonedResponse, getHeadersGuard(this[kHeaders]))
Expand Down
3 changes: 2 additions & 1 deletion test/fetch/fire-and-forget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ test('does not need the body to be consumed to continue', { timeout: 180_000, sk
// eslint-disable-next-line no-undef
gc(true)
const array = new Array(batch)
for (let i = 0; i < batch; i++) {
for (let i = 0; i < batch; i += 2) {
array[i] = fetch(url).catch(() => {})
array[i + 1] = fetch(url).then(r => r.clone()).catch(() => {})
}
await Promise.all(array)
await sleep(delay)
Expand Down
Loading