mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Revert "stream: revert fix cloned webstreams not being unref'd"
This reverts commit 8d20b641a2.
PR-URL: https://github.com/nodejs/node/pull/53144
Fixes: https://github.com/nodejs/node/issues/53143
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
1 parent
e6d9fbece2
commit
cffd2cc0c9
3 files changed
+30
No files matched your search
@@ -146,6 +146,8 @@ class CrossRealmTransformReadableSource {
|
||||
error);
|
||||
port.close();
|
||||
};
|
||||
|
||||
port.unref();
|
||||
}
|
||||
|
||||
start(controller) {
|
||||
@@ -219,6 +221,7 @@ class CrossRealmTransformWritableSink {
|
||||
port.close();
|
||||
};
|
||||
|
||||
port.unref();
|
||||
}
|
||||
|
||||
start(controller) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
'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);
|
||||
@@ -454,12 +454,23 @@ 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();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user