summaryrefslogtreecommitdiff
path: root/runtime/ops/worker_host.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-12-11 15:56:45 +0100
committerGitHub <noreply@github.com>2021-12-11 15:56:45 +0100
commit0dec9b4381e0aa1d4b75ab5837cb75598f19c727 (patch)
tree960f9bd48c5b733317c5592d9843f315883413f8 /runtime/ops/worker_host.rs
parent13d7d5722771bf8c4de7083dc0f964dfffcb318a (diff)
fix: op_set_exit_code (#13034)
Fixes "op_set_exit_code" by sharing a single "Arc" between all workers (via "op state") instead of having a "global" value stored in "deno_runtime" crate. As a consequence setting an exit code is always scoped to a tree of workers, instead of being overridable if there are multiple worker tree (like in "deno test --jobs" subcommand). Refactored "cli/main.rs" functions to return "Result<i32, AnyError>" instead of "Result<(), AnyError>" so they can return exit code.
Diffstat (limited to 'runtime/ops/worker_host.rs')
-rw-r--r--runtime/ops/worker_host.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs
index e9eb380e0..f290b3833 100644
--- a/runtime/ops/worker_host.rs
+++ b/runtime/ops/worker_host.rs
@@ -23,6 +23,7 @@ use log::debug;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
+use std::sync::atomic::AtomicI32;
use std::sync::Arc;
use std::thread::JoinHandle;
@@ -34,6 +35,7 @@ pub struct CreateWebWorkerArgs {
pub main_module: ModuleSpecifier,
pub use_deno_namespace: bool,
pub worker_type: WebWorkerType,
+ pub maybe_exit_code: Option<Arc<AtomicI32>>,
}
pub type CreateWebWorkerCb = dyn Fn(CreateWebWorkerArgs) -> (WebWorker, SendableWebWorkerHandle)
@@ -166,7 +168,11 @@ fn op_create_worker(
parent_permissions.clone()
};
let parent_permissions = parent_permissions.clone();
-
+ // `try_borrow` here, because worker might have been started without
+ // access to `Deno` namespace.
+ // TODO(bartlomieju): can a situation happen when parent doesn't
+ // have access to `exit_code` but the child does?
+ let maybe_exit_code = state.try_borrow::<Arc<AtomicI32>>().cloned();
let worker_id = state.take::<WorkerId>();
let create_module_loader = state.take::<CreateWebWorkerCbHolder>();
state.put::<CreateWebWorkerCbHolder>(create_module_loader.clone());
@@ -199,6 +205,7 @@ fn op_create_worker(
main_module: module_specifier.clone(),
use_deno_namespace,
worker_type,
+ maybe_exit_code,
});
// Send thread safe handle from newly created worker to host thread