Files
node/test/parallel/test-webstreams-clone-unref.js
T
James M Snell e443953656 stream: fix cloned webstreams not being unref'd
When cloning a `ReadableStream` and `WritableStream`, both use an
internal `MessageChannel` to communicate with the original stream.
Those, however, previously were not unref'd which would lead to the
process not exiting if the stream was not fully consumed.

Fixes: https://github.com/nodejs/node/issues/44985
PR-URL: https://github.com/nodejs/node/pull/51255
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
2024-01-02 15:05:26 -03:00

17 lines
471 B
JavaScript

'use strict';
require('../common');
const { ok } = require('node:assert');
// This test verifies that cloned ReadableStream and WritableStream instances
// do not keep the process alive. The test fails if it timesout (it should just
// exit immediately)
const rs1 = new ReadableStream();
const ws1 = new WritableStream();
const [rs2, ws2] = structuredClone([rs1, ws1], { transfer: [rs1, ws1] });
ok(rs2 instanceof ReadableStream);
ok(ws2 instanceof WritableStream);