expenses opened issue #11339:
I'm attempting to run wasm code inside a
#[tokio::main] async mainfunction and atokio::spawned task. I tried switching towasmtime_wasi::runtime::spawninstead (it's very unclear what this module does) but that just prevented the spawned code from running.Full stack trace:
thread 'tokio-runtime-worker' panicked at /home/ashley/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasmtime-wasi-35.0.0/src/runtime.rs:108:15: Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks. stack backtrace: 0: 0x5626812064d2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc04c8f544ab24d66 1: 0x56268122eb53 - core::fmt::write::hfe57b7174b7d8eab 2: 0x5626812025f3 - std::io::Write::write_fmt::h154385efa8565236 3: 0x562681206322 - std::sys::backtrace::BacktraceLock::print::h0c8f24e22f5873a8 4: 0x562681207382 - std::panicking::default_hook::{{closure}}::hd07d57e6a602c8e4 5: 0x562681207185 - std::panicking::default_hook::h63d12f7d95bd91ed 6: 0x562681207d22 - std::panicking::rust_panic_with_hook::h33b18b24045abff4 7: 0x562681207a96 - std::panicking::begin_panic_handler::{{closure}}::hf8313cc2fd0126bc 8: 0x5626812069d9 - std::sys::backtrace::__rust_end_short_backtrace::h57fe07c8aea5c98a 9: 0x56268120775d - __rustc[95feac21a9532783]::rust_begin_unwind 10: 0x56267ffd8910 - core::panicking::panic_fmt::hd54fb667be51beea 11: 0x562680237c3f - tokio::runtime::context::runtime::enter_runtime::h76284ea528f7c045 12: 0x5626801fddcb - wasmtime_wasi::p2::host::io::<impl wasmtime_wasi::p2::bindings::sync::generated::wasi::io::streams::HostInputStream for wasmtime_wasi_io::IoImpl<T>>::blocking_read::hf8ace88840c3ac67 13: 0x56268004cb45 - wasmtime::runtime::component::func::host::call_host::h7c578e6ccb7f0c8c 14: 0x5626800fa2d1 - <core::result::Result<T,E> as wasmtime::runtime::vm::traphandlers::HostResult>::maybe_catch_unwind::h42efaa2e63de1d2c 15: 0x56267fff5ecc - wasmtime::runtime::component::func::host::HostFunc::entrypoint::he6bcc58df9bc7a52 16: 0x7f022cb4d623 - <unknown> 17: 0x7f022cb484bc - <unknown> 18: 0x7f022cb45b24 - <unknown> 19: 0x7f022cb47b0a - <unknown> 20: 0x7f022cb295e4 - <unknown> 21: 0x7f022cb251b5 - <unknown> 22: 0x7f022caf798d - <unknown> 23: 0x7f022cb0b749 - <unknown> 24: 0x7f022cae6b9b - <unknown> 25: 0x7f022cae649f - <unknown> 26: 0x7f022caf7b9f - <unknown> 27: 0x7f022cafe237 - <unknown> 28: 0x7f022cafe1ac - <unknown> 29: 0x7f022cb22c3d - <unknown> 30: 0x7f022caf99d2 - <unknown> 31: 0x7f022cae508b - <unknown> 32: 0x7f022cb43c9a - <unknown> 33: 0x7f022cb4abbb - <unknown> 34: 0x5626806ec2b9 - wasmtime_setjmp_35_0_0 35: 0x56268026e6e3 - wasmtime::runtime::func::invoke_wasm_and_catch_traps::ha6ecf8931187d6d6 36: 0x56268029527e - wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl::h88d3a3472f30eafe 37: 0x56268028044f - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7d898c7887df9401 38: 0x56267ff6e86f - wasmtime_internal_fiber::unix::fiber_start::hf8765a3dcbf39dea 39: 0x562680d2fba8 - wasmtime_fiber_start_35_0_0 40: 0x56268061c46e - wasmtime::runtime::fiber::resume_fiber::hd70459f30e734893 41: 0x56268061ccf1 - <wasmtime::runtime::fiber::FiberFuture as core::future::future::Future>::poll::had00c3ff3cce9fac 42: 0x56268029e4f4 - <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll::hde0e8fe73cc92937 43: 0x5626802b5d43 - rssdb_core::Client::update_source::{{closure}}::h5833ba5baf511f9b 44: 0x5626802b1f12 - rssdb_core::Client::setup_update_loop::{{closure}}::hba96005202db263e 45: 0x5626802b1504 - tokio::runtime::task::core::Core<T,S>::poll::he719bfa08e2aa8bc 46: 0x562680286fdd - tokio::runtime::task::harness::Harness<T,S>::poll::hf657a3fda2cd17cb 47: 0x5626811c4903 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h4729362dffd41a38 48: 0x5626811c423f - tokio::runtime::scheduler::multi_thread::worker::Context::run::h5e9304a42dc97c2c 49: 0x5626811bc0f8 - tokio::runtime::context::scoped::Scoped<T>::set::h6b3548bded3816e2 50: 0x5626811cb7d8 - tokio::runtime::context::runtime::enter_runtime::h9b1dd17e9a3ce6c8 51: 0x5626811c39bd - tokio::runtime::scheduler::multi_thread::worker::run::h09fe2c5b155d5920 52: 0x5626811ca0e6 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::h8dc0eb1dcd46c75d 53: 0x5626811ceb77 - tokio::runtime::task::core::Core<T,S>::poll::h9f69a6cc0a5a5137 54: 0x5626811b2541 - tokio::runtime::task::harness::Harness<T,S>::poll::h78602c7a80941702 55: 0x5626811c887a - tokio::runtime::blocking::pool::Inner::run::h3e335aeb132a149b 56: 0x5626811c1670 - std::sys::backtrace::__rust_begin_short_backtrace::h7f66a5e0db9d2d4d 57: 0x5626811d4792 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2d211650b26d66bb 58: 0x562681209abb - std::sys::pal::unix::thread::Thread::new::thread_start::h2717d4f9aca577e6 59: 0x7f022fa9af08 - start_thread 60: 0x7f022fb230ac - __clone3 61: 0x0 - <unknown>
expenses added the bug label to Issue #11339.
pchickey closed issue #11339:
I'm attempting to run wasm code inside a
#[tokio::main] async mainfunction and atokio::spawned task. I tried switching towasmtime_wasi::runtime::spawninstead (it's very unclear what this module does) but that just prevented the spawned code from running.Full stack trace:
thread 'tokio-runtime-worker' panicked at /home/ashley/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasmtime-wasi-35.0.0/src/runtime.rs:108:15: Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks. stack backtrace: 0: 0x5626812064d2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc04c8f544ab24d66 1: 0x56268122eb53 - core::fmt::write::hfe57b7174b7d8eab 2: 0x5626812025f3 - std::io::Write::write_fmt::h154385efa8565236 3: 0x562681206322 - std::sys::backtrace::BacktraceLock::print::h0c8f24e22f5873a8 4: 0x562681207382 - std::panicking::default_hook::{{closure}}::hd07d57e6a602c8e4 5: 0x562681207185 - std::panicking::default_hook::h63d12f7d95bd91ed 6: 0x562681207d22 - std::panicking::rust_panic_with_hook::h33b18b24045abff4 7: 0x562681207a96 - std::panicking::begin_panic_handler::{{closure}}::hf8313cc2fd0126bc 8: 0x5626812069d9 - std::sys::backtrace::__rust_end_short_backtrace::h57fe07c8aea5c98a 9: 0x56268120775d - __rustc[95feac21a9532783]::rust_begin_unwind 10: 0x56267ffd8910 - core::panicking::panic_fmt::hd54fb667be51beea 11: 0x562680237c3f - tokio::runtime::context::runtime::enter_runtime::h76284ea528f7c045 12: 0x5626801fddcb - wasmtime_wasi::p2::host::io::<impl wasmtime_wasi::p2::bindings::sync::generated::wasi::io::streams::HostInputStream for wasmtime_wasi_io::IoImpl<T>>::blocking_read::hf8ace88840c3ac67 13: 0x56268004cb45 - wasmtime::runtime::component::func::host::call_host::h7c578e6ccb7f0c8c 14: 0x5626800fa2d1 - <core::result::Result<T,E> as wasmtime::runtime::vm::traphandlers::HostResult>::maybe_catch_unwind::h42efaa2e63de1d2c 15: 0x56267fff5ecc - wasmtime::runtime::component::func::host::HostFunc::entrypoint::he6bcc58df9bc7a52 16: 0x7f022cb4d623 - <unknown> 17: 0x7f022cb484bc - <unknown> 18: 0x7f022cb45b24 - <unknown> 19: 0x7f022cb47b0a - <unknown> 20: 0x7f022cb295e4 - <unknown> 21: 0x7f022cb251b5 - <unknown> 22: 0x7f022caf798d - <unknown> 23: 0x7f022cb0b749 - <unknown> 24: 0x7f022cae6b9b - <unknown> 25: 0x7f022cae649f - <unknown> 26: 0x7f022caf7b9f - <unknown> 27: 0x7f022cafe237 - <unknown> 28: 0x7f022cafe1ac - <unknown> 29: 0x7f022cb22c3d - <unknown> 30: 0x7f022caf99d2 - <unknown> 31: 0x7f022cae508b - <unknown> 32: 0x7f022cb43c9a - <unknown> 33: 0x7f022cb4abbb - <unknown> 34: 0x5626806ec2b9 - wasmtime_setjmp_35_0_0 35: 0x56268026e6e3 - wasmtime::runtime::func::invoke_wasm_and_catch_traps::ha6ecf8931187d6d6 36: 0x56268029527e - wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl::h88d3a3472f30eafe 37: 0x56268028044f - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7d898c7887df9401 38: 0x56267ff6e86f - wasmtime_internal_fiber::unix::fiber_start::hf8765a3dcbf39dea 39: 0x562680d2fba8 - wasmtime_fiber_start_35_0_0 40: 0x56268061c46e - wasmtime::runtime::fiber::resume_fiber::hd70459f30e734893 41: 0x56268061ccf1 - <wasmtime::runtime::fiber::FiberFuture as core::future::future::Future>::poll::had00c3ff3cce9fac 42: 0x56268029e4f4 - <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll::hde0e8fe73cc92937 43: 0x5626802b5d43 - rssdb_core::Client::update_source::{{closure}}::h5833ba5baf511f9b 44: 0x5626802b1f12 - rssdb_core::Client::setup_update_loop::{{closure}}::hba96005202db263e 45: 0x5626802b1504 - tokio::runtime::task::core::Core<T,S>::poll::he719bfa08e2aa8bc 46: 0x562680286fdd - tokio::runtime::task::harness::Harness<T,S>::poll::hf657a3fda2cd17cb 47: 0x5626811c4903 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h4729362dffd41a38 48: 0x5626811c423f - tokio::runtime::scheduler::multi_thread::worker::Context::run::h5e9304a42dc97c2c 49: 0x5626811bc0f8 - tokio::runtime::context::scoped::Scoped<T>::set::h6b3548bded3816e2 50: 0x5626811cb7d8 - tokio::runtime::context::runtime::enter_runtime::h9b1dd17e9a3ce6c8 51: 0x5626811c39bd - tokio::runtime::scheduler::multi_thread::worker::run::h09fe2c5b155d5920 52: 0x5626811ca0e6 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::h8dc0eb1dcd46c75d 53: 0x5626811ceb77 - tokio::runtime::task::core::Core<T,S>::poll::h9f69a6cc0a5a5137 54: 0x5626811b2541 - tokio::runtime::task::harness::Harness<T,S>::poll::h78602c7a80941702 55: 0x5626811c887a - tokio::runtime::blocking::pool::Inner::run::h3e335aeb132a149b 56: 0x5626811c1670 - std::sys::backtrace::__rust_begin_short_backtrace::h7f66a5e0db9d2d4d 57: 0x5626811d4792 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2d211650b26d66bb 58: 0x562681209abb - std::sys::pal::unix::thread::Thread::new::thread_start::h2717d4f9aca577e6 59: 0x7f022fa9af08 - start_thread 60: 0x7f022fb230ac - __clone3 61: 0x0 - <unknown>
pchickey commented on issue #11339:
If you are using tokio you need to use wasmtime in with Config::enable_async(true), use all of the async_ variations such as
instantiate_async, andcall_async, and also use wasmtime_wasi::p2::add_to_linker_async. Feel free to reopen with a minimized case for reproducing your error if making those changes doesn't fix your issue.
expenses commented on issue #11339:
ahh,
add_to_linker_asyncdid it, thanks!
Last updated: Dec 06 2025 at 06:05 UTC