Skip to content
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

fix: allow cloned stream to be unref'd #1700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/fetch/body.js
Expand Up @@ -261,13 +261,16 @@ function cloneBody (body) {
// 1. Let « out1, out2 » be the result of teeing body’s stream.
const [out1, out2] = body.stream.tee()
const out2Clone = structuredClone(out2, { transfer: [out2] })
// This, for whatever reasons, unrefs out2Clone which allows
// the process to exit by itself.
const [, finalClone] = out2Clone.tee()

// 2. Set body’s stream to out1.
body.stream = out1

// 3. Return a body whose stream is out2 and other members are copied from body.
return {
stream: out2Clone,
stream: finalClone,
length: body.length,
source: body.source
}
Expand Down
5 changes: 1 addition & 4 deletions test/fetch/response.js
@@ -1,6 +1,6 @@
'use strict'

const { test, teardown } = require('tap')
const { test } = require('tap')
const {
Response
} = require('../../')
Expand Down Expand Up @@ -248,6 +248,3 @@ test('constructing Response with third party FormData body', async (t) => {
t.equal(contentType[0], 'multipart/form-data; boundary')
t.ok((await res.text()).startsWith(`--${contentType[1]}`))
})

// This is needed due to https://github.com/nodejs/node/issues/44985
teardown(() => process.exit(0))