forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(workers): Make
worker.terminate()
not immediately kill the isol…
…ate (denoland#12831) Due to a bug in V8, terminating an isolate while a module with top-level await is being evaluated would crash the process. This change makes it so calling `worker.terminate()` will signal the worker to terminate at the next iteration of the event loop, and it schedules a proper termination of the worker's isolate after 2 seconds.
- Loading branch information
Andreu Botella
committed
Nov 29, 2021
1 parent
5178e09
commit 4a13c32
Showing
4 changed files
with
96 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Test for https://github.com/denoland/deno/issues/12658 | ||
// | ||
// If a worker is terminated immediately after construction, and the worker's | ||
// main module uses top-level await, V8 has a chance to crash. | ||
// | ||
// These crashes are so rare in debug mode that I've only seen them once. They | ||
// happen a lot more often in release mode. | ||
|
||
const workerModule = ` | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
`; | ||
|
||
// Iterating 10 times to increase the likelihood of triggering the crash, at | ||
// least in release mode. | ||
for (let i = 0; i < 10; i++) { | ||
const worker = new Worker( | ||
`data:application/javascript;base64,${btoa(workerModule)}`, | ||
{ type: "module" }, | ||
); | ||
worker.terminate(); | ||
} |
Empty file.
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