fix(runtime/web_worker): Use biased select when getting module result (#14553)

This commit is contained in:
Nayeem Rahman 2022-05-10 10:26:57 +01:00 committed by Bert Belder
parent 09ad149ffb
commit 7e530ce1c9
No known key found for this signature in database
GPG Key ID: 7A77887B2E2ED461
6 changed files with 28 additions and 3 deletions

View File

@ -236,7 +236,7 @@ jobs:
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: 11-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
key: 12-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
# In main branch, always creates fresh cache
- name: Cache build output (main)
@ -252,7 +252,7 @@ jobs:
!./target/*/*.zip
!./target/*/*.tar.gz
key: |
11-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
12-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
# Restore cache from the latest 'main' branch build.
- name: Cache build output (PR)
@ -268,7 +268,7 @@ jobs:
!./target/*/*.tar.gz
key: never_saved
restore-keys: |
11-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
12-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
# Don't save cache after building PRs or branches other than 'main'.
- name: Skip save cache (PR)

View File

@ -2714,6 +2714,14 @@ itest!(event_listener_error_immediate_exit {
exit_code: 1,
});
// https://github.com/denoland/deno/pull/14159#issuecomment-1092285446
itest!(event_listener_error_immediate_exit_worker {
args:
"run --quiet --unstable -A event_listener_error_immediate_exit_worker.ts",
output: "event_listener_error_immediate_exit_worker.ts.out",
exit_code: 1,
});
itest!(set_timeout_error {
args: "run --quiet set_timeout_error.ts",
output: "set_timeout_error.ts.out",

View File

@ -0,0 +1,4 @@
new Worker(
new URL("event_listener_error_immediate_exit.ts", import.meta.url).href,
{ type: "module", deno: { namespace: true } },
);

View File

@ -0,0 +1,8 @@
1
error: Uncaught (in worker "") Error: bar
throw new Error("bar");
^
at [WILDCARD]/event_listener_error_immediate_exit.ts:4:9
at [WILDCARD]/event_listener_error_immediate_exit.ts:11:1
error: Uncaught (in promise) Error: Unhandled error in child worker.
at [WILDCARD]

View File

@ -557,6 +557,8 @@ impl WebWorker {
let id = self.preload_module(module_specifier, false).await?;
let mut receiver = self.js_runtime.mod_evaluate(id);
tokio::select! {
biased;
maybe_result = &mut receiver => {
debug!("received module evaluate {:#?}", maybe_result);
maybe_result.expect("Module evaluation result not provided.")
@ -579,6 +581,8 @@ impl WebWorker {
) -> Result<(), AnyError> {
let mut receiver = self.js_runtime.mod_evaluate(id);
tokio::select! {
biased;
maybe_result = &mut receiver => {
debug!("received worker module evaluate {:#?}", maybe_result);
// If `None` is returned it means that runtime was destroyed before

View File

@ -304,6 +304,7 @@ impl MainWorker {
) -> T {
loop {
tokio::select! {
biased;
result = &mut fut => {
return result;
}