mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
5c5f4ea1d6
This panic could happen in the following cases: - A non-fatal error being thrown from a worker, that doesn't terminate the worker's execution, but propagates to the main thread without being handled, and makes the main thread terminate. - A nested worker being alive while its parent worker gets terminated. - A race condition if the main event loop terminates the worker as part of its last task, but the worker doesn't fully terminate before the main event loop stops running. This panic happens because a worker's event loop should have pending ops as long as the worker isn't closed or terminated – but if an event loop finishes running while it has living workers, its associated `WorkerThread` structs will be dropped, closing the channels that keep those ops pending. This change adds a `Drop` implementation to `WorkerThread`, which terminates the worker without waiting for a response. This fixes the panic, and makes it so nested workers are automatically terminated once any of their ancestors is closed or terminated. This change also refactors a worker's termination code into a `WorkerThread::terminate()` method. Closes #11342. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
12 lines
500 B
JavaScript
12 lines
500 B
JavaScript
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// https://github.com/denoland/deno/issues/11342
|
|
// Test for a panic that happens when the main thread's event loop finishes
|
|
// running while the worker's event loop is still spinning.
|
|
|
|
// The exception thrown in the worker will not terminate the worker, but it will
|
|
// propagate to the main thread and cause it to exit.
|
|
new Worker(
|
|
new URL("./workers/drop_handle_race.js", import.meta.url).href,
|
|
{ type: "module" },
|
|
);
|