Skip to content

Commit c7eb5f0

Browse files
authored
fix: allow cloned stream to be unref'd (nodejs#1700)
1 parent ad251bb commit c7eb5f0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/fetch/body.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,16 @@ function cloneBody (body) {
261261
// 1. Let « out1, out2 » be the result of teeing body’s stream.
262262
const [out1, out2] = body.stream.tee()
263263
const out2Clone = structuredClone(out2, { transfer: [out2] })
264+
// This, for whatever reasons, unrefs out2Clone which allows
265+
// the process to exit by itself.
266+
const [, finalClone] = out2Clone.tee()
264267

265268
// 2. Set body’s stream to out1.
266269
body.stream = out1
267270

268271
// 3. Return a body whose stream is out2 and other members are copied from body.
269272
return {
270-
stream: out2Clone,
273+
stream: finalClone,
271274
length: body.length,
272275
source: body.source
273276
}

test/fetch/response.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test, teardown } = require('tap')
3+
const { test } = require('tap')
44
const {
55
Response
66
} = require('../../')
@@ -248,6 +248,3 @@ test('constructing Response with third party FormData body', async (t) => {
248248
t.equal(contentType[0], 'multipart/form-data; boundary')
249249
t.ok((await res.text()).startsWith(`--${contentType[1]}`))
250250
})
251-
252-
// This is needed due to https://github.com/nodejs/node/issues/44985
253-
teardown(() => process.exit(0))

0 commit comments

Comments
 (0)