From f26c8bcf3167069ccd8ac3beb9185d1bf480a83f Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 22 Oct 2024 01:41:08 -0700 Subject: refactor(runtime/ops): use concrete error types (#26409) --- runtime/web_worker.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index f560ce17e..04cd3305e 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -166,7 +166,10 @@ pub struct WebWorkerInternalHandle { impl WebWorkerInternalHandle { /// Post WorkerEvent to parent as a worker - pub fn post_event(&self, event: WorkerControlEvent) -> Result<(), AnyError> { + pub fn post_event( + &self, + event: WorkerControlEvent, + ) -> Result<(), mpsc::TrySendError> { let mut sender = self.sender.clone(); // If the channel is closed, // the worker must have terminated but the termination message has not yet been received. @@ -176,8 +179,7 @@ impl WebWorkerInternalHandle { self.has_terminated.store(true, Ordering::SeqCst); return Ok(()); } - sender.try_send(event)?; - Ok(()) + sender.try_send(event) } /// Check if this worker is terminated or being terminated @@ -263,11 +265,9 @@ impl WebWorkerHandle { /// Get the WorkerEvent with lock /// Return error if more than one listener tries to get event #[allow(clippy::await_holding_refcell_ref)] // TODO(ry) remove! - pub async fn get_control_event( - &self, - ) -> Result, AnyError> { + pub async fn get_control_event(&self) -> Option { let mut receiver = self.receiver.borrow_mut(); - Ok(receiver.next().await) + receiver.next().await } /// Terminate the worker -- cgit v1.2.3 From 700f54a13cce0fcdcf19d1893e3254579c7347f4 Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 6 Nov 2024 15:08:26 +0100 Subject: fix(ext/node): better inspector support (#26471) implement local inspector future changes: - wire up InspectorServer to enable open/close/url - wire up connectToMainThread Fixes https://github.com/denoland/deno/issues/25004 --- runtime/web_worker.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 04cd3305e..61e5c7702 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -562,7 +562,7 @@ impl WebWorker { extension_transpiler: Some(Rc::new(|specifier, source| { maybe_transpile_source(specifier, source) })), - inspector: services.maybe_inspector_server.is_some(), + inspector: true, feature_checker: Some(services.feature_checker), op_metrics_factory_fn, import_meta_resolve_callback: Some(Box::new( @@ -579,18 +579,18 @@ impl WebWorker { js_runtime.op_state().borrow_mut().put(op_summary_metrics); } + // Put inspector handle into the op state so we can put a breakpoint when + // executing a CJS entrypoint. + let op_state = js_runtime.op_state(); + let inspector = js_runtime.inspector(); + op_state.borrow_mut().put(inspector); + if let Some(server) = services.maybe_inspector_server { server.register_inspector( options.main_module.to_string(), &mut js_runtime, false, ); - - // Put inspector handle into the op state so we can put a breakpoint when - // executing a CJS entrypoint. - let op_state = js_runtime.op_state(); - let inspector = js_runtime.inspector(); - op_state.borrow_mut().put(inspector); } let (internal_handle, external_handle) = { -- cgit v1.2.3 From aa546189be730163ee5370029e4dfdb3b454ab96 Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 13 Nov 2024 11:38:46 +0100 Subject: feat: OpenTelemetry Tracing API and Exporting (#26710) Initial import of OTEL code supporting tracing. Metrics soon to come. Implements APIs for https://jsr.io/@deno/otel so that code using OpenTelemetry.js just works tm. There is still a lot of work to do with configuration and adding built-in tracing to core APIs, which will come in followup PRs. --------- Co-authored-by: Luca Casonato --- runtime/web_worker.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 61e5c7702..d81c82c50 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -505,6 +505,9 @@ impl WebWorker { ), ops::fs_events::deno_fs_events::init_ops_and_esm(), ops::os::deno_os_worker::init_ops_and_esm(), + ops::otel::deno_otel::init_ops_and_esm( + options.bootstrap.otel_config.clone(), + ), ops::permissions::deno_permissions::init_ops_and_esm(), ops::process::deno_process::init_ops_and_esm( services.npm_process_state_provider, -- cgit v1.2.3 From f091d1ad69b4e5217ae3272b641171781a372c4f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 13 Nov 2024 10:10:09 -0500 Subject: feat(node): stabilize detecting if CJS via `"type": "commonjs"` in a package.json (#26439) This will respect `"type": "commonjs"` in a package.json to determine if `.js`/`.jsx`/`.ts`/.tsx` files are CJS or ESM. If the file is found to be ESM it will be loaded as ESM though. --- runtime/web_worker.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index d81c82c50..e27229153 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -393,6 +393,13 @@ pub struct WebWorker { maybe_worker_metadata: Option, } +impl Drop for WebWorker { + fn drop(&mut self) { + // clean up the package.json thread local cache + node_resolver::PackageJsonThreadLocalCache::clear(); + } +} + impl WebWorker { pub fn bootstrap_from_options( services: WebWorkerServiceOptions, -- cgit v1.2.3 From 4e899d48cffa95617266dd8f9aef54603a87ad82 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 14 Nov 2024 13:16:28 +0100 Subject: fix: otel resiliency (#26857) Improving the breadth of collected data, and ensuring that the collected data is more likely to be successfully reported. - Use `log` crate in more places - Hook up `log` crate to otel - Switch to process-wide otel processors - Handle places that use `process::exit` Also adds a more robust testing framework, with a deterministic tracing setting. Refs: https://github.com/denoland/deno/issues/26852 --- runtime/web_worker.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index e27229153..b056e01fc 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -512,9 +512,7 @@ impl WebWorker { ), ops::fs_events::deno_fs_events::init_ops_and_esm(), ops::os::deno_os_worker::init_ops_and_esm(), - ops::otel::deno_otel::init_ops_and_esm( - options.bootstrap.otel_config.clone(), - ), + ops::otel::deno_otel::init_ops_and_esm(), ops::permissions::deno_permissions::init_ops_and_esm(), ops::process::deno_process::init_ops_and_esm( services.npm_process_state_provider, @@ -831,13 +829,12 @@ impl WebWorker { // TODO(mmastrac): we don't want to test this w/classic workers because // WPT triggers a failure here. This is only exposed via --enable-testing-features-do-not-use. - #[allow(clippy::print_stderr)] if self.worker_type == WebWorkerType::Module { panic!( "coding error: either js is polling or the worker is terminated" ); } else { - eprintln!("classic worker terminated unexpectedly"); + log::error!("classic worker terminated unexpectedly"); Poll::Ready(Ok(())) } } @@ -905,7 +902,6 @@ impl WebWorker { } } -#[allow(clippy::print_stderr)] fn print_worker_error( error: &AnyError, name: &str, @@ -918,7 +914,7 @@ fn print_worker_error( }, None => error.to_string(), }; - eprintln!( + log::error!( "{}: Uncaught (in worker \"{}\") {}", colors::red_bold("error"), name, -- cgit v1.2.3 From c9baf3849fdbe161a9251a712a71e2b91eeabf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 15 Nov 2024 09:33:03 +0000 Subject: perf: use available system memory for v8 isolate memory limit (#26868) Instead of using the default 1.4Gb limit (which was meant for browser tabs) configure V8 to set the heap limit to the amount of memory available in the system. Closes https://github.com/denoland/deno/issues/23424 Closes https://github.com/denoland/deno/issues/26435 Closes https://github.com/denoland/deno/issues/21226 --- runtime/web_worker.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index b056e01fc..8e0c870d1 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -361,6 +361,8 @@ pub struct WebWorkerOptions { pub extensions: Vec, pub startup_snapshot: Option<&'static [u8]>, pub unsafely_ignore_certificate_errors: Option>, + /// Optional isolate creation parameters, such as heap limits. + pub create_params: Option, pub seed: Option, pub create_web_worker_cb: Arc, pub format_js_error_fn: Option>, @@ -563,6 +565,7 @@ impl WebWorker { let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(services.module_loader), startup_snapshot: options.startup_snapshot, + create_params: options.create_params, get_error_class_fn: options.get_error_class_fn, shared_array_buffer_store: services.shared_array_buffer_store, compiled_wasm_module_store: services.compiled_wasm_module_store, -- cgit v1.2.3 From 9f26ca450936da66e57dad2206d0d11363e7b35c Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Tue, 19 Nov 2024 10:46:24 +0900 Subject: feat(ext/http): Make http server parameters configurable (#26785) This commit makes http server parameters configurable on the extension initialization via two callbacks users can provide. The main motivation behind this change is to allow `deno_http` users to tune the HTTP/2 server to suit their needs, although Deno CLI users will not benefit from it as no JavaScript interface is exposed to set these parameters currently. It is up to users whether to provide hook functions. If not provided, the default configuration from hyper crate will be used. --- runtime/web_worker.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 8e0c870d1..a282d11b9 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -497,7 +497,9 @@ impl WebWorker { ), deno_cron::deno_cron::init_ops_and_esm(LocalCronHandler::new()), deno_napi::deno_napi::init_ops_and_esm::(), - deno_http::deno_http::init_ops_and_esm::(), + deno_http::deno_http::init_ops_and_esm::( + deno_http::Options::default(), + ), deno_io::deno_io::init_ops_and_esm(Some(options.stdio)), deno_fs::deno_fs::init_ops_and_esm::( services.fs.clone(), -- cgit v1.2.3