diff --git a/lib/wasi/src/bin_factory/exec.rs b/lib/wasi/src/bin_factory/exec.rs index 073e75e3b6d..ffde2fd4557 100644 --- a/lib/wasi/src/bin_factory/exec.rs +++ b/lib/wasi/src/bin_factory/exec.rs @@ -15,7 +15,8 @@ use crate::{ WasiFunctionEnv, WasiRuntime, }; -pub fn spawn_exec( +#[tracing::instrument(level = "trace", skip_all, fields(%name, %binary.package_name))] +pub async fn spawn_exec( binary: BinaryPackage, name: &str, store: Store, @@ -26,7 +27,9 @@ pub fn spawn_exec( // The deterministic id for this engine let compiler = store.engine().deterministic_id(); - let module = compiled_modules.get_compiled_module(&**runtime, binary.hash().as_str(), compiler); + let module = compiled_modules + .get_compiled_module(&**runtime, binary.hash().as_str(), compiler) + .await; let module = match (module, binary.entry.as_ref()) { (Some(a), _) => a, @@ -45,12 +48,9 @@ pub fn spawn_exec( } let module = module?; - compiled_modules.set_compiled_module( - &**runtime, - binary.hash().as_str(), - compiler, - &module, - ); + compiled_modules + .set_compiled_module(&**runtime, binary.hash().as_str(), compiler, &module) + .await; module } (None, None) => { @@ -220,6 +220,7 @@ impl BinFactory { &self.runtime, &self.cache, ) + .await }) } diff --git a/lib/wasi/src/bin_factory/module_cache.rs b/lib/wasi/src/bin_factory/module_cache.rs index a90dfd511a0..1286cebd157 100644 --- a/lib/wasi/src/bin_factory/module_cache.rs +++ b/lib/wasi/src/bin_factory/module_cache.rs @@ -59,7 +59,7 @@ impl ModuleCache { }) } - pub fn get_compiled_module( + pub async fn get_compiled_module( &self, runtime: &dyn WasiRuntime, data_hash: &str, @@ -69,12 +69,10 @@ impl ModuleCache { let engine = runtime.engine()?; let tasks = runtime.task_manager(); - tasks - .block_on(async { self.0.load(&key, &engine, tasks).await }) - .ok() + self.0.load(&key, &engine, tasks).await.ok() } - pub fn set_compiled_module( + pub async fn set_compiled_module( &self, runtime: &dyn WasiRuntime, data_hash: &str, @@ -84,7 +82,7 @@ impl ModuleCache { let key = format!("{}-{}", data_hash, compiler); let tasks = runtime.task_manager(); - let result = tasks.block_on(async { self.0.save(&key, module, tasks).await }); + let result = self.0.save(&key, module, tasks).await; if let Err(e) = result { tracing::warn!( diff --git a/lib/wasi/src/os/command/builtins/cmd_wasmer.rs b/lib/wasi/src/os/command/builtins/cmd_wasmer.rs index edbb4471a8f..39fc9be89b9 100644 --- a/lib/wasi/src/os/command/builtins/cmd_wasmer.rs +++ b/lib/wasi/src/os/command/builtins/cmd_wasmer.rs @@ -81,7 +81,9 @@ impl CmdWasmer { // Get the binary if let Some(binary) = self.get_package(what.clone()) { // Now run the module - spawn_exec(binary, name, store, env, &self.runtime, &self.cache) + parent_ctx.data().tasks().block_on(async { + spawn_exec(binary, name, store, env, &self.runtime, &self.cache).await + }) } else { parent_ctx.data().tasks().block_on(async move { let _ = stderr_write( diff --git a/lib/wasi/src/os/console/mod.rs b/lib/wasi/src/os/console/mod.rs index 201d3c9e6e5..a758230f1f3 100644 --- a/lib/wasi/src/os/console/mod.rs +++ b/lib/wasi/src/os/console/mod.rs @@ -242,14 +242,14 @@ impl Console { // Build the config // Run the binary - let process = spawn_exec( + let process = tasks.block_on(spawn_exec( binary, prog, store, env, &self.runtime, self.compiled_modules.as_ref(), - )?; + ))?; // Return the process Ok((process, wasi_process)) diff --git a/lib/wasi/src/syscalls/wasix/proc_exec.rs b/lib/wasi/src/syscalls/wasix/proc_exec.rs index 6e1160f6c1e..218ccb3a860 100644 --- a/lib/wasi/src/syscalls/wasix/proc_exec.rs +++ b/lib/wasi/src/syscalls/wasix/proc_exec.rs @@ -101,18 +101,13 @@ pub fn proc_exec( let new_store = new_store.take().unwrap(); let env = config.take().unwrap(); - tasks.block_on(async { - let name_inner = name.clone(); - let ret = bin_factory.spawn( - name_inner, - new_store, - env, - ) - .await; + let name_inner = name.clone(); + __asyncify_light(ctx.data(), None, async { + let ret = bin_factory.spawn(name_inner, new_store, env).await; match ret { Ok(ret) => { trace!(%child_pid, "spawned sub-process"); - }, + } Err(err) => { err_exit_code = conv_bus_err_to_exit_code(err); @@ -127,10 +122,13 @@ pub fn proc_exec( &ctx, format!("wasm execute failed [{}] - {}\n", name.as_str(), err) .as_bytes(), - ).await; + ) + .await; } } - }) + + Ok(()) + }); } } };