| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e6d9fbe commit cffd2cc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,6 +146,8 @@ class CrossRealmTransformReadableSource { | |||
| 146 | 146 | error); | |
| 147 | 147 | port.close(); | |
| 148 | 148 | }; | |
| 149 | + | ||
| 150 | + port.unref(); | ||
| 149 | 151 | } | |
| 150 | 152 | ||
| 151 | 153 | start(controller) { | |
@@ -219,6 +221,7 @@ class CrossRealmTransformWritableSink { | |||
| 219 | 221 | port.close(); | |
| 220 | 222 | }; | |
| 221 | 223 | ||
| 224 | + port.unref(); | ||
| 222 | 225 | } | |
| 223 | 226 | ||
| 224 | 227 | start(controller) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const { ok } = require('node:assert'); | ||
| 5 | + | ||
| 6 | + // This test verifies that cloned ReadableStream and WritableStream instances | ||
| 7 | + // do not keep the process alive. The test fails if it timesout (it should just | ||
| 8 | + // exit immediately) | ||
| 9 | + | ||
| 10 | + const rs1 = new ReadableStream(); | ||
| 11 | + const ws1 = new WritableStream(); | ||
| 12 | + | ||
| 13 | + const [rs2, ws2] = structuredClone([rs1, ws1], { transfer: [rs1, ws1] }); | ||
| 14 | + | ||
| 15 | + ok(rs2 instanceof ReadableStream); | ||
| 16 | + ok(ws2 instanceof WritableStream); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -454,12 +454,23 @@ const theData = 'hello'; | |||
| 454 | 454 | tracker.verify(); | |
| 455 | 455 | }); | |
| 456 | 456 | ||
| 457 | + // We create an interval to keep the event loop alive while | ||
| 458 | + // we wait for the stream read to complete. The reason this is needed is because there's | ||
| 459 | + // otherwise nothing to keep the worker thread event loop alive long enough to actually | ||
| 460 | + // complete the read from the stream. Under the covers the ReadableStream uses an | ||
| 461 | + // unref'd MessagePort to communicate with the main thread. Because the MessagePort | ||
| 462 | + // is unref'd, it's existence would not keep the thread alive on its own. There was previously | ||
| 463 | + // a bug where this MessagePort was ref'd which would block the thread and main thread | ||
| 464 | + // from terminating at all unless the stream was consumed/closed. | ||
| 465 | + const i = setInterval(() => {}, 1000); | ||
| 466 | + | ||
| 457 | 467 | parentPort.onmessage = tracker.calls(({ data }) => { | |
| 458 | 468 | assert(isReadableStream(data)); | |
| 459 | 469 | const reader = data.getReader(); | |
| 460 | 470 | reader.read().then(tracker.calls((result) => { | |
| 461 | 471 | assert(!result.done); | |
| 462 | 472 | assert(result.value instanceof Uint8Array); | |
| 473 | + clearInterval(i); | ||
| 463 | 474 | })); | |
| 464 | 475 | parentPort.close(); | |
| 465 | 476 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments