Skip to content

Commit

Permalink
fix: Don't panic when a worker is closed in the reactions to a wasm o…
Browse files Browse the repository at this point in the history
…peration. (denoland#12270)
  • Loading branch information
Andreu Botella committed Sep 30, 2021
1 parent 68e5cda commit a2632c8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
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

0 comments on commit a2632c8

Please sign in to comment.