Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't panic when a worker is closed in the reactions to a wasm operation. #12270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ itest!(worker_message_before_close {
output: "worker_message_before_close.js.out",
});

itest!(worker_close_in_wasm_reactions {
args: "run --quiet --reload --allow-read worker_close_in_wasm_reactions.js",
output: "worker_close_in_wasm_reactions.js.out",
});

#[test]
fn no_validate_asm() {
let output = util::deno_cmd()
Expand Down
10 changes: 10 additions & 0 deletions cli/tests/testdata/worker_close_in_wasm_reactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

// https://github.com/denoland/deno/issues/12263
// Test for a panic that happens when a worker is closed in the reactions of a
// WASM async operation.

new Worker(
new URL("./workers/close_in_wasm_reactions.js", import.meta.url),
{ type: "module" },
);
1 change: 1 addition & 0 deletions cli/tests/testdata/worker_close_in_wasm_reactions.js.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: CompileError: WebAssembly.compile(): expected string length @+10
21 changes: 21 additions & 0 deletions cli/tests/testdata/workers/close_in_wasm_reactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://github.com/denoland/deno/issues/12263
// Test for a panic that happens when a worker is closed in the reactions of a
// WASM async operation.

// The minimum valid wasm module, plus two additional zero bytes.
const buffer = new Uint8Array([
0x00,
0x61,
0x73,
0x6D,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
]);
WebAssembly.compile(buffer).catch((err) => {
console.log("Error:", err);
self.close();
});
4 changes: 4 additions & 0 deletions core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,10 @@ impl JsRuntime {
return exception_to_err_result(tc_scope, exception, false);
}

if tc_scope.has_terminated() || tc_scope.is_execution_terminating() {
break;
}

let is_done = is_done.unwrap();
if is_done.is_true() {
break;
Expand Down