From c7eb5f011cc87312eff67c6dc7deff119c093cb5 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Fri, 14 Oct 2022 04:12:57 -0400 Subject: [PATCH] fix: allow cloned stream to be unref'd (#1700) --- lib/fetch/body.js | 5 ++++- test/fetch/response.js | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 2895fb0e0ea..e5eb610b1a4 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -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 } diff --git a/test/fetch/response.js b/test/fetch/response.js index c0e388d1223..2342f0927ff 100644 --- a/test/fetch/response.js +++ b/test/fetch/response.js @@ -1,6 +1,6 @@ 'use strict' -const { test, teardown } = require('tap') +const { test } = require('tap') const { Response } = require('../../') @@ -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))