-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panic due to runaway promises #9
Comments
Full trace
|
Hmm.. first of all lets assume the first error (no such elem) causes the second (eventloop borked due to earlier panic) So i'll focus on the 'no such elem' error.. you're using new_resolving_promise_async which adds a ref to a map (autoidmap) in the realm... then after going async the realm still exists (by id) but it's map (promise_cache) does not have the id anymore... so either
could it be that your code causes the second case? meaning the realm could be destroyed while not all promises are resolved yet? e.g. async log calls being discarded |
I'm not calling js_promise_cache_consume anywhere. |
ok, it's an edge case which i need to fix, and just log but even then there are apparently promises which you have not awaited and which will not resolve... |
ok, I changed the AutoIdMap to have random ID's this means that the chance of your dangling Promise resolving the wrong newer promises is 1 in (usize::MAX / the number of Promises in the new realm).. when a dangling promise is resolve it will log an error, DISCLAIMER released as utils:0.6 and qjs_runtime 0.9 due to changes in the JSRealm trait |
Thanks a lot for the quick turnaround. These errors happen in development due to missing await that will eventually be fixed. |
This happens when using Promise.all([...multiplePromises]), and if one of them throws an error leaving all the other promises to continue running until complete or rejected. In our case, the context is removed as soon as the first promise throws an error. thread panic occurred: panicked at 'no such elem', /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/auto_id_map.rs:133:29
backtrace: 0: backtrace::backtrace::libunwind::trace
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.67/src/backtrace/libunwind.rs:93:5
backtrace::backtrace::trace_unsynchronized
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.67/src/backtrace/mod.rs:66:5
1: backtrace::backtrace::trace
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.67/src/backtrace/mod.rs:53:14
2: backtrace::capture::Backtrace::create
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.67/src/capture.rs:176:9
3: backtrace::capture::Backtrace::new
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.67/src/capture.rs:140:22
4: cloudio::main::{{closure}}::{{closure}}
at io-server/src/main.rs:115:25
5: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:2002:9
std::panicking::rust_panic_with_hook
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:692:13
6: std::panicking::begin_panic_handler::{{closure}}
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:579:13
7: std::sys_common::backtrace::__rust_end_short_backtrace
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:137:18
8: rust_begin_unwind
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
9: core::panicking::panic_fmt
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
10: core::panicking::panic_display
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:147:5
11: core::panicking::panic_str
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:131:5
12: core::option::expect_failed
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/option.rs:1924:5
13: core::option::Option<T>::expect
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/option.rs:786:21
14: hirofa_utils::auto_id_map::AutoIdMap<T>::remove
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/auto_id_map.rs:133:9
15: quickjs_runtime::quickjsrealmadapter::QuickJsRealmAdapter::consume_cached_obj
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/quickjsrealmadapter.rs:297:9
16: <quickjs_runtime::quickjsrealmadapter::QuickJsRealmAdapter as hirofa_utils::js_utils::adapters::JsRealmAdapter>::js_cache_dispose
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/quickjsrealmadapter.rs:823:17
17: hirofa_utils::js_utils::facades::values::CachedJsObjectRef::new::{{closure}}::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/js_utils/facades/values.rs:45:25
18: quickjs_runtime::quickjsruntimeadapter::QuickJsRuntimeAdapter::do_with::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/quickjsruntimeadapter.rs:604:13
19: std::thread::local::LocalKey<T>::try_with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:446:16
20: std::thread::local::LocalKey<T>::with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:422:9
21: quickjs_runtime::quickjsruntimeadapter::QuickJsRuntimeAdapter::do_with
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/quickjsruntimeadapter.rs:596:19
22: quickjs_runtime::facades::QuickjsRuntimeFacadeInner::add_rt_task_to_event_loop_void::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/facades.rs:138:45
23: quickjs_runtime::facades::QuickjsRuntimeFacadeInner::add_task_to_event_loop_void::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/quickjs_runtime-0.9.0/src/facades.rs:74:13
24: core::ops::function::FnOnce::call_once{{vtable.shim}}
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/ops/function.rs:250:5
25: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
26: hirofa_utils::eventloop::EventLoop::new::{{closure}}::{{closure}}::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/eventloop.rs:92:52
27: <futures_task::future_obj::LocalFutureObj<T> as core::future::future::Future>::poll
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-task-0.3.27/src/future_obj.rs:84:18
28: <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.27/src/stream/futures_unordered/mod.rs:518:17
29: futures_util::stream::stream::StreamExt::poll_next_unpin
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.27/src/stream/stream/mod.rs:1632:9
30: futures_executor::local_pool::LocalPool::poll_pool
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.27/src/local_pool.rs:279:28
31: futures_executor::local_pool::LocalPool::run_until_stalled::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.27/src/local_pool.rs:254:33
32: futures_executor::local_pool::run_executor::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.27/src/local_pool.rs:90:37
33: std::thread::local::LocalKey<T>::try_with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:446:16
34: std::thread::local::LocalKey<T>::with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:422:9
35: futures_executor::local_pool::run_executor
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.27/src/local_pool.rs:86:5
36: futures_executor::local_pool::LocalPool::run_until_stalled
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.27/src/local_pool.rs:254:9
37: hirofa_utils::eventloop::EventLoop::new::{{closure}}::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/eventloop.rs:95:21
38: std::thread::local::LocalKey<T>::try_with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:446:16
39: std::thread::local::LocalKey<T>::with
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/local.rs:422:9
40: hirofa_utils::eventloop::EventLoop::new::{{closure}}
at /dir/.cargo/registry/src/github.com-1ecc6299db9ec823/hirofa_utils-0.6.1/src/eventloop.rs:72:13
41: std::sys_common::backtrace::__rust_begin_short_backtrace
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:121:18
42: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/mod.rs:558:17
43: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panic/unwind_safe.rs:271:9
44: std::panicking::try::do_call
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:483:40
45: ___rust_try
46: std::panicking::try
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:447:19
47: std::panic::catch_unwind
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs:140:14
48: std::thread::Builder::spawn_unchecked_::{{closure}}
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/thread/mod.rs:557:30
49: core::ops::function::FnOnce::call_once{{vtable.shim}}
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/ops/function.rs:250:5
50: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
std::sys::unix::thread::Thread::new::thread_start
at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
51: __pthread_start |
I tried to fix this on my fork, but not sure if it's ok to change the return param of js_cache_consume from JSValueRef to Option; hence didn't create a PR. |
One other place
|
Full trace
|
Hi, Reverting to _opt and logging error is fine for now.. someday that's going to resolve/reject a completely different promise in your new context.. the solution is probably something like storing Weakrefs to the Realm instead of an id string.. please leave this tocke topen for that |
Oh. That would be even more dangerous. Will this be resolved if I don't reuse the context id? I was trying to avoid creation of too many contexts for a given session request. |
yeah if you use a different context id every time it will be safe since resolving this definitively needs some refactoring in utils and in quickjs_runtime i'd like to finish a large refactor i'm working on first... |
In a complex use case where there are nested promise calls, the runtime is crashing with the following panics. Do you think these can be handled without panicking? I'm trying to create a simple, reproducible code sample, but unable to get it to panic.
The text was updated successfully, but these errors were encountered: