Skip to content

Commit 6bba634

Browse files
mcollinamarco-ippolito
authored andcommitted
Revert "stream: fix cloned webstreams not being unref'd"
This reverts commit 4d3923a. PR-URL: nodejs#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>
1 parent f7c0be2 commit 6bba634

File tree

5 files changed

+1
-34
lines changed

5 files changed

+1
-34
lines changed

lib/internal/webstreams/readablestream.js

-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,6 @@ class ReadableStream {
598598

599599
[kTransferList]() {
600600
const { port1, port2 } = new MessageChannel();
601-
port1.unref();
602-
port2.unref();
603601
this[kState].transfer.port1 = port1;
604602
this[kState].transfer.port2 = port2;
605603
return [ port2 ];

lib/internal/webstreams/transfer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ class CrossRealmTransformReadableSource {
143143
error);
144144
port.close();
145145
};
146-
147-
port.unref();
148146
}
149147

150148
start(controller) {
@@ -212,7 +210,7 @@ class CrossRealmTransformWritableSink {
212210
error);
213211
port.close();
214212
};
215-
port.unref();
213+
216214
}
217215

218216
start(controller) {

lib/internal/webstreams/writablestream.js

-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ class WritableStream {
274274

275275
[kTransferList]() {
276276
const { port1, port2 } = new MessageChannel();
277-
port1.unref();
278-
port2.unref();
279277
this[kState].transfer.port1 = port1;
280278
this[kState].transfer.port2 = port2;
281279
return [ port2 ];

test/parallel/test-webstreams-clone-unref.js

-16
This file was deleted.

test/parallel/test-whatwg-webstreams-transfer.js

-11
Original file line numberDiff line numberDiff line change
@@ -464,23 +464,12 @@ const theData = 'hello';
464464
tracker.verify();
465465
});
466466
467-
// We create an interval to keep the event loop alive while
468-
// we wait for the stream read to complete. The reason this is needed is because there's
469-
// otherwise nothing to keep the worker thread event loop alive long enough to actually
470-
// complete the read from the stream. Under the covers the ReadableStream uses an
471-
// unref'd MessagePort to communicate with the main thread. Because the MessagePort
472-
// is unref'd, it's existence would not keep the thread alive on its own. There was previously
473-
// a bug where this MessagePort was ref'd which would block the thread and main thread
474-
// from terminating at all unless the stream was consumed/closed.
475-
const i = setInterval(() => {}, 1000);
476-
477467
parentPort.onmessage = tracker.calls(({ data }) => {
478468
assert(isReadableStream(data));
479469
const reader = data.getReader();
480470
reader.read().then(tracker.calls((result) => {
481471
assert(!result.done);
482472
assert(result.value instanceof Uint8Array);
483-
clearInterval(i);
484473
}));
485474
parentPort.close();
486475
});

0 commit comments

Comments
 (0)