Revert "stream: fix cloned webstreams not being unref'd"

This reverts commit 4d3923aaba.

PR-URL: https://github.com/nodejs/node/pull/51491
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Matteo Collina 2024-01-16 16:45:52 +01:00 committed by Node.js GitHub Bot
parent a7729737cf
commit 8e8245196a
5 changed files with 1 additions and 34 deletions

View File

@ -598,8 +598,6 @@ class ReadableStream {
[kTransferList]() {
const { port1, port2 } = new MessageChannel();
port1.unref();
port2.unref();
this[kState].transfer.port1 = port1;
this[kState].transfer.port2 = port2;
return [ port2 ];

View File

@ -143,8 +143,6 @@ class CrossRealmTransformReadableSource {
error);
port.close();
};
port.unref();
}
start(controller) {
@ -212,7 +210,7 @@ class CrossRealmTransformWritableSink {
error);
port.close();
};
port.unref();
}
start(controller) {

View File

@ -274,8 +274,6 @@ class WritableStream {
[kTransferList]() {
const { port1, port2 } = new MessageChannel();
port1.unref();
port2.unref();
this[kState].transfer.port1 = port1;
this[kState].transfer.port2 = port2;
return [ port2 ];

View File

@ -1,16 +0,0 @@
'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);

View File

@ -464,23 +464,12 @@ const theData = 'hello';
tracker.verify();
});
// We create an interval to keep the event loop alive while
// we wait for the stream read to complete. The reason this is needed is because there's
// otherwise nothing to keep the worker thread event loop alive long enough to actually
// complete the read from the stream. Under the covers the ReadableStream uses an
// unref'd MessagePort to communicate with the main thread. Because the MessagePort
// is unref'd, it's existence would not keep the thread alive on its own. There was previously
// a bug where this MessagePort was ref'd which would block the thread and main thread
// from terminating at all unless the stream was consumed/closed.
const i = setInterval(() => {}, 1000);
parentPort.onmessage = tracker.calls(({ data }) => {
assert(isReadableStream(data));
const reader = data.getReader();
reader.read().then(tracker.calls((result) => {
assert(!result.done);
assert(result.value instanceof Uint8Array);
clearInterval(i);
}));
parentPort.close();
});