I'm still trying to work with JsFutures in Wasm, but I discovered the following behaviour. When running the code
use wasm_bindgen_futures::JsFuture;
use web_sys::window;
use js_sys::Promise;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
async fn test_wait_ms() {
console_error_panic_hook::set_once();
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
log::debug!("Running test");
wait_ms(100).await;
wait_ms(100).await;
panic!("Show stack/heap");
}
async fn wait_ms(ms: i32) {
let promise = Promise::new(&mut |yes, _| {
let win = window().unwrap();
win.set_timeout_with_callback_and_timeout_and_arguments_0(&yes, ms)
.unwrap();
});
let js_fut = JsFuture::from(promise);
js_fut.await;
}
I see a long stack-trace after the panic
(there must be a proper way to print the stack / heap) which grows longer if I add more wait_ms
in the test-method.
Does that mean that Wasm is not correctly cleaning up the JsFuture.await
? Or does it only mean that I don't know how to read the stack/heap trace produced by panic
?
Here is the output from the above code:
console.<computed> @ (index):15
(anonymous) @ wasm-bindgen-test:593
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_error_4bb6c2a97407129a @ wasm-bindgen-test:591
$console_error_panic_hook::error::h5ee162e8c00de58d @ wasm-bindgen-test_bg.wasm:0x2b4f0d
$console_error_panic_hook::hook_impl::hf848f1eeb18f8b7d @ wasm-bindgen-test_bg.wasm:0x21a73a
$console_error_panic_hook::hook::h750d81068679507e @ wasm-bindgen-test_bg.wasm:0x359d0b
$core::ops::function::Fn::call::h1609cb0630d0bbf1 @ wasm-bindgen-test_bg.wasm:0x34266b
$std::panicking::rust_panic_with_hook::he9bfe03219d715ba @ wasm-bindgen-test_bg.wasm:0x282706
$std::panicking::begin_panic::{{closure}}::he40fef5e17f6b58e @ wasm-bindgen-test_bg.wasm:0x2cb221
$std::sys_common::backtrace::__rust_end_short_backtrace::hd8ae9a7213f7132a @ wasm-bindgen-test_bg.wasm:0x2f3753
$std::panicking::begin_panic::hcfcf2bc744e752a2 @ wasm-bindgen-test_bg.wasm:0x32e89f
$wasm_webrtc::test_wait_ms::test_wait_ms::{{closure}}::h1db7019032ef2421 @ wasm-bindgen-test_bg.wasm:0x181bea
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd6f9d6d2994b98f2 @ wasm-bindgen-test_bg.wasm:0x2aa15b
$wasm_bindgen_test::__rt::Context::execute_async::{{closure}}::h656701822149525f @ wasm-bindgen-test_bg.wasm:0x204a56
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6d304df6f7bf69ff @ wasm-bindgen-test_bg.wasm:0x2a9e5f
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::{{closure}}::h8eb6ed72ffbe352a @ wasm-bindgen-test_bg.wasm:0x2d7253
$wasm_bindgen::convert::closures::invoke0_mut::h2c699ce350272107 @ wasm-bindgen-test_bg.wasm:0x2bbdf1
__wbg_adapter_54 @ wasm-bindgen-test:364
cb0 @ wasm-bindgen-test:536
window.__wbg_test_invoke @ (index):25
(anonymous) @ wasm-bindgen-test:541
handleError @ wasm-bindgen-test:369
imports.wbg.__wbg_wbgtestinvoke_6d22b7d64550c12f @ wasm-bindgen-test:529
$wasm_bindgen_test::__rt::__wbg_test_invoke::h5911ea9eca5183b7 @ wasm-bindgen-test_bg.wasm:0x250c48
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::hd4695e4a25d6c3a8 @ wasm-bindgen-test_bg.wasm:0x2bd317
$scoped_tls::ScopedKey<T>::set::h711076e3a91c0bdf @ wasm-bindgen-test_bg.wasm:0x26e371
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::h5bba7ba7a2e0e0c9 @ wasm-bindgen-test_bg.wasm:0x17f779
$<wasm_bindgen_test::__rt::ExecuteTests as core::future::future::Future>::poll::h2174ed68299da2c2 @ wasm-bindgen-test_bg.wasm:0xed29b
$wasm_bindgen_test::__rt::Context::run::{{closure}}::hc7d4368f014d2456 @ wasm-bindgen-test_bg.wasm:0x1f6e7c
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h8b334f1807679992 @ wasm-bindgen-test_bg.wasm:0x27aee7
$wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::hf3c00e2c51b5e763 @ wasm-bindgen-test_bg.wasm:0x195533
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2c38d676517e2203 @ wasm-bindgen-test_bg.wasm:0x2aa8a8
$wasm_bindgen_futures::task::singlethread::Task::run::h8c5979b40af7554e @ wasm-bindgen-test_bg.wasm:0x1e2236
$wasm_bindgen_futures::queue::QueueState::run_all::h2311101bcc23bb9c @ wasm-bindgen-test_bg.wasm:0x2041aa
$wasm_bindgen_futures::queue::Queue::new::{{closure}}::h5ae3ab5cab960077 @ wasm-bindgen-test_bg.wasm:0x3089a8
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hed2c3548a8b32456 @ wasm-bindgen-test_bg.wasm:0x293997
__wbg_adapter_41 @ wasm-bindgen-test:268
real @ wasm-bindgen-test:201
Promise.then (async)
(anonymous) @ wasm-bindgen-test:871
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_then_c2361a9d5c9a4fcb @ wasm-bindgen-test:870
$js_sys::Promise::then::hea5fad77105c5bb9 @ wasm-bindgen-test_bg.wasm:0x301ca4
$wasm_bindgen_futures::queue::Queue::push_task::h3f6874a6247774a6 @ wasm-bindgen-test_bg.wasm:0x2383bf
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::{{closure}}::hb50f853c0f646b13 @ wasm-bindgen-test_bg.wasm:0x336b87
$std::thread::local::LocalKey<T>::try_with::h8b1d60d0756bcecb @ wasm-bindgen-test_bg.wasm:0x291e7b
$std::thread::local::LocalKey<T>::with::h05495a9c85e65f64 @ wasm-bindgen-test_bg.wasm:0x2fcbc2
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::h4261b943cb25dea5 @ wasm-bindgen-test_bg.wasm:0x2a98c1
$wasm_bindgen_futures::task::singlethread::Task::into_raw_waker::raw_wake::h5af0691eca61cb4a @ wasm-bindgen-test_bg.wasm:0x301c37
$core::task::wake::Waker::wake::h6300b2e573224863 @ wasm-bindgen-test_bg.wasm:0x31e083
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::finish::hba302f5e6889d0c7 @ wasm-bindgen-test_bg.wasm:0x1964e1
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::{{closure}}::h50a92c72efa5bed8 @ wasm-bindgen-test_bg.wasm:0x2e269d
$core::ops::function::FnOnce::call_once::hfbf3c39e2cb7b4e6 @ wasm-bindgen-test_bg.wasm:0x2fe198
$<T as wasm_bindgen::closure::WasmClosureFnOnce<A,R>>::into_fn_mut::{{closure}}::h3e7b4776c0c0ecec @ wasm-bindgen-test_bg.wasm:0x2f77d0
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hed2c3548a8b32456 @ wasm-bindgen-test_bg.wasm:0x293997
__wbg_adapter_41 @ wasm-bindgen-test:268
real @ wasm-bindgen-test:201
Promise.then (async)
(anonymous) @ wasm-bindgen-test:875
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_then_6c9a4bf55755f9b8 @ wasm-bindgen-test:874
$js_sys::Promise::then2::h60b2eed0742f1f57 @ wasm-bindgen-test_bg.wasm:0x2e2885
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::h0dd8cb6e262cd257 @ wasm-bindgen-test_bg.wasm:0x15e24e
$wasm_webrtc::test_wait_ms::wait_ms::{{closure}}::h38a83862219ffad9 @ wasm-bindgen-test_bg.wasm:0x1e2a97
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h438655e6fea14639 @ wasm-bindgen-test_bg.wasm:0x2a9c22
$wasm_webrtc::test_wait_ms::test_wait_ms::{{closure}}::h1db7019032ef2421 @ wasm-bindgen-test_bg.wasm:0x181b4f
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd6f9d6d2994b98f2 @ wasm-bindgen-test_bg.wasm:0x2aa15b
$wasm_bindgen_test::__rt::Context::execute_async::{{closure}}::h656701822149525f @ wasm-bindgen-test_bg.wasm:0x204a56
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6d304df6f7bf69ff @ wasm-bindgen-test_bg.wasm:0x2a9e5f
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::{{closure}}::h8eb6ed72ffbe352a @ wasm-bindgen-test_bg.wasm:0x2d7253
$wasm_bindgen::convert::closures::invoke0_mut::h2c699ce350272107 @ wasm-bindgen-test_bg.wasm:0x2bbdf1
__wbg_adapter_54 @ wasm-bindgen-test:364
cb0 @ wasm-bindgen-test:536
window.__wbg_test_invoke @ (index):25
(anonymous) @ wasm-bindgen-test:541
handleError @ wasm-bindgen-test:369
imports.wbg.__wbg_wbgtestinvoke_6d22b7d64550c12f @ wasm-bindgen-test:529
$wasm_bindgen_test::__rt::__wbg_test_invoke::h5911ea9eca5183b7 @ wasm-bindgen-test_bg.wasm:0x250c48
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::hd4695e4a25d6c3a8 @ wasm-bindgen-test_bg.wasm:0x2bd317
$scoped_tls::ScopedKey<T>::set::h711076e3a91c0bdf @ wasm-bindgen-test_bg.wasm:0x26e371
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::h5bba7ba7a2e0e0c9 @ wasm-bindgen-test_bg.wasm:0x17f779
$<wasm_bindgen_test::__rt::ExecuteTests as core::future::future::Future>::poll::h2174ed68299da2c2 @ wasm-bindgen-test_bg.wasm:0xed29b
$wasm_bindgen_test::__rt::Context::run::{{closure}}::hc7d4368f014d2456 @ wasm-bindgen-test_bg.wasm:0x1f6e7c
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h8b334f1807679992 @ wasm-bindgen-test_bg.wasm:0x27aee7
$wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::hf3c00e2c51b5e763 @ wasm-bindgen-test_bg.wasm:0x195533
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2c38d676517e2203 @ wasm-bindgen-test_bg.wasm:0x2aa8a8
$wasm_bindgen_futures::task::singlethread::Task::run::h8c5979b40af7554e @ wasm-bindgen-test_bg.wasm:0x1e2236
$wasm_bindgen_futures::queue::QueueState::run_all::h2311101bcc23bb9c @ wasm-bindgen-test_bg.wasm:0x2041aa
$wasm_bindgen_futures::queue::Queue::new::{{closure}}::h5ae3ab5cab960077 @ wasm-bindgen-test_bg.wasm:0x3089a8
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hed2c3548a8b32456 @ wasm-bindgen-test_bg.wasm:0x293997
__wbg_adapter_41 @ wasm-bindgen-test:268
real @ wasm-bindgen-test:201
Promise.then (async)
(anonymous) @ wasm-bindgen-test:871
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_then_c2361a9d5c9a4fcb @ wasm-bindgen-test:870
$js_sys::Promise::then::hea5fad77105c5bb9 @ wasm-bindgen-test_bg.wasm:0x301ca4
$wasm_bindgen_futures::queue::Queue::push_task::h3f6874a6247774a6 @ wasm-bindgen-test_bg.wasm:0x2383bf
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::{{closure}}::hb50f853c0f646b13 @ wasm-bindgen-test_bg.wasm:0x336b87
$std::thread::local::LocalKey<T>::try_with::h8b1d60d0756bcecb @ wasm-bindgen-test_bg.wasm:0x291e7b
$std::thread::local::LocalKey<T>::with::h05495a9c85e65f64 @ wasm-bindgen-test_bg.wasm:0x2fcbc2
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::h4261b943cb25dea5 @ wasm-bindgen-test_bg.wasm:0x2a98c1
$wasm_bindgen_futures::task::singlethread::Task::into_raw_waker::raw_wake::h5af0691eca61cb4a @ wasm-bindgen-test_bg.wasm:0x301c37
$core::task::wake::Waker::wake::h6300b2e573224863 @ wasm-bindgen-test_bg.wasm:0x31e083
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::finish::hba302f5e6889d0c7 @ wasm-bindgen-test_bg.wasm:0x1964e1
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::{{closure}}::h50a92c72efa5bed8 @ wasm-bindgen-test_bg.wasm:0x2e269d
$core::ops::function::FnOnce::call_once::hfbf3c39e2cb7b4e6 @ wasm-bindgen-test_bg.wasm:0x2fe198
$<T as wasm_bindgen::closure::WasmClosureFnOnce<A,R>>::into_fn_mut::{{closure}}::h3e7b4776c0c0ecec @ wasm-bindgen-test_bg.wasm:0x2f77d0
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hed2c3548a8b32456 @ wasm-bindgen-test_bg.wasm:0x293997
__wbg_adapter_41 @ wasm-bindgen-test:268
real @ wasm-bindgen-test:201
Promise.then (async)
(anonymous) @ wasm-bindgen-test:875
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_then_6c9a4bf55755f9b8 @ wasm-bindgen-test:874
$js_sys::Promise::then2::h60b2eed0742f1f57 @ wasm-bindgen-test_bg.wasm:0x2e2885
$<wasm_bindgen_futures::JsFuture as core::convert::From<js_sys::Promise>>::from::h0dd8cb6e262cd257 @ wasm-bindgen-test_bg.wasm:0x15e24e
$wasm_webrtc::test_wait_ms::wait_ms::{{closure}}::h38a83862219ffad9 @ wasm-bindgen-test_bg.wasm:0x1e2a97
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h438655e6fea14639 @ wasm-bindgen-test_bg.wasm:0x2a9c22
$wasm_webrtc::test_wait_ms::test_wait_ms::{{closure}}::h1db7019032ef2421 @ wasm-bindgen-test_bg.wasm:0x181a39
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd6f9d6d2994b98f2 @ wasm-bindgen-test_bg.wasm:0x2aa15b
$wasm_bindgen_test::__rt::Context::execute_async::{{closure}}::h656701822149525f @ wasm-bindgen-test_bg.wasm:0x204a56
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6d304df6f7bf69ff @ wasm-bindgen-test_bg.wasm:0x2a9e5f
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::{{closure}}::h8eb6ed72ffbe352a @ wasm-bindgen-test_bg.wasm:0x2d7253
$wasm_bindgen::convert::closures::invoke0_mut::h2c699ce350272107 @ wasm-bindgen-test_bg.wasm:0x2bbdf1
__wbg_adapter_54 @ wasm-bindgen-test:364
cb0 @ wasm-bindgen-test:536
window.__wbg_test_invoke @ (index):25
(anonymous) @ wasm-bindgen-test:541
handleError @ wasm-bindgen-test:369
imports.wbg.__wbg_wbgtestinvoke_6d22b7d64550c12f @ wasm-bindgen-test:529
$wasm_bindgen_test::__rt::__wbg_test_invoke::h5911ea9eca5183b7 @ wasm-bindgen-test_bg.wasm:0x250c48
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::{{closure}}::hd4695e4a25d6c3a8 @ wasm-bindgen-test_bg.wasm:0x2bd317
$scoped_tls::ScopedKey<T>::set::h711076e3a91c0bdf @ wasm-bindgen-test_bg.wasm:0x26e371
$<wasm_bindgen_test::__rt::TestFuture<F> as core::future::future::Future>::poll::h5bba7ba7a2e0e0c9 @ wasm-bindgen-test_bg.wasm:0x17f779
$<wasm_bindgen_test::__rt::ExecuteTests as core::future::future::Future>::poll::h2174ed68299da2c2 @ wasm-bindgen-test_bg.wasm:0xed653
$wasm_bindgen_test::__rt::Context::run::{{closure}}::hc7d4368f014d2456 @ wasm-bindgen-test_bg.wasm:0x1f6e7c
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h8b334f1807679992 @ wasm-bindgen-test_bg.wasm:0x27aee7
$wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::hf3c00e2c51b5e763 @ wasm-bindgen-test_bg.wasm:0x195533
$<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2c38d676517e2203 @ wasm-bindgen-test_bg.wasm:0x2aa8a8
$wasm_bindgen_futures::task::singlethread::Task::run::h8c5979b40af7554e @ wasm-bindgen-test_bg.wasm:0x1e2236
$wasm_bindgen_futures::queue::QueueState::run_all::h2311101bcc23bb9c @ wasm-bindgen-test_bg.wasm:0x2041aa
$wasm_bindgen_futures::queue::Queue::new::{{closure}}::h5ae3ab5cab960077 @ wasm-bindgen-test_bg.wasm:0x3089a8
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hed2c3548a8b32456 @ wasm-bindgen-test_bg.wasm:0x293997
__wbg_adapter_41 @ wasm-bindgen-test:268
real @ wasm-bindgen-test:201
Promise.then (async)
(anonymous) @ wasm-bindgen-test:871
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_then_c2361a9d5c9a4fcb @ wasm-bindgen-test:870
$js_sys::Promise::then::hea5fad77105c5bb9 @ wasm-bindgen-test_bg.wasm:0x301ca4
$wasm_bindgen_futures::queue::Queue::push_task::h3f6874a6247774a6 @ wasm-bindgen-test_bg.wasm:0x2383bf
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::{{closure}}::hb50f853c0f646b13 @ wasm-bindgen-test_bg.wasm:0x336b87
$std::thread::local::LocalKey<T>::try_with::h8b1d60d0756bcecb @ wasm-bindgen-test_bg.wasm:0x291e7b
$std::thread::local::LocalKey<T>::with::h05495a9c85e65f64 @ wasm-bindgen-test_bg.wasm:0x2fcbc2
$wasm_bindgen_futures::task::singlethread::Task::wake_by_ref::h4261b943cb25dea5 @ wasm-bindgen-test_bg.wasm:0x2a98c1
$wasm_bindgen_futures::task::singlethread::Task::spawn::h3c8b4f4db92cc819 @ wasm-bindgen-test_bg.wasm:0x1aa2c1
$wasm_bindgen_futures::spawn_local::h3b59c349ec0381ee @ wasm-bindgen-test_bg.wasm:0x21c11f
$wasm_bindgen_futures::future_to_promise::{{closure}}::h9e2eccf3d06354e5 @ wasm-bindgen-test_bg.wasm:0x250e35
$wasm_bindgen::convert::closures::invoke2_mut::h2dfa9bf43d1cf4d1 @ wasm-bindgen-test_bg.wasm:0x27f7e5
__wbg_adapter_179 @ wasm-bindgen-test:394
cb0 @ wasm-bindgen-test:855
(anonymous) @ wasm-bindgen-test:860
logError @ wasm-bindgen-test:218
imports.wbg.__wbg_new_c143a4f563f78c4e @ wasm-bindgen-test:848
$js_sys::Promise::new::h8e59a0bd4c565e98 @ wasm-bindgen-test_bg.wasm:0x2f4052
$wasm_bindgen_futures::future_to_promise::h8534f38060476630 @ wasm-bindgen-test_bg.wasm:0x27e949
$wasm_bindgen_test::__rt::Context::run::h6582b0a7dbf5ac7b @ wasm-bindgen-test_bg.wasm:0x13a674
$wasmbindgentestcontext_run @ wasm-bindgen-test_bg.wasm:0x254b3a
run @ wasm-bindgen-test:467
main @ run.js:33
async function (async)
main @ run.js:18
(anonymous) @ run.js:41