-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix deadlock when cloning webstreams
- Loading branch information
Showing
4 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/parallel/test-webstreams-using-structuredclone-exit-process.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { Worker } = require('worker_threads'); | ||
const { once } = require('node:events'); | ||
|
||
const worker = new Worker( | ||
` | ||
const { ReadableStream } = require('stream/web'); | ||
const rs = new ReadableStream(); | ||
const cloned = structuredClone(rs, { transfer: [rs] }); | ||
`, | ||
{ eval: true }, | ||
); | ||
|
||
const worker2 = new Worker( | ||
` | ||
const { WritableStream } = require('stream/web'); | ||
const ws = new WritableStream(); | ||
const cloned = structuredClone(ws, { transfer: [ws] }); | ||
`, | ||
{ eval: true }, | ||
); | ||
|
||
(async () => { | ||
// A timer is used here to detect the end of a process. | ||
const timer = setTimeout(common.mustNotCall(), common.platformTimeout(10000)); | ||
|
||
await Promise.all([once(worker, 'exit'), once(worker2, 'exit')]); | ||
|
||
clearTimeout(timer); | ||
})().then(common.mustCall()); |