Skip to content

Commit

Permalink
fix: allow cloned stream to be unref'd (nodejs#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and metcoder95 committed Dec 26, 2022
1 parent 192fc8b commit ae883e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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))

0 comments on commit ae883e6

Please sign in to comment.