Skip to content
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

[bug] *intermittent* GTK may only be used from the main thread #11312

Open
zakhenry opened this issue Oct 10, 2024 · 16 comments · May be fixed by tauri-apps/tao#1036
Open

[bug] *intermittent* GTK may only be used from the main thread #11312

zakhenry opened this issue Oct 10, 2024 · 16 comments · May be fixed by tauri-apps/tao#1036
Labels
platform: Linux status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@zakhenry
Copy link

zakhenry commented Oct 10, 2024

Describe the bug

I'm afraid this is a particularly hard one to reproduce, but hopefully the stack trace helps someone point me in the right direction.

I have a tauri app that I am launching in integration tests with tokio::process::spawn (my app is launched as a cli tool). So as the app is running as a sub process, it is running in the main thread and everything should be fine.

The issue arises within the integration test when I am making some calls to the web frontend and sometimes (roughly 50% of the time) I get the following error:

thread 'tokio-runtime-worker' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/webkit2gtk-2.0.1/src/auto/uri_scheme_response.rs:26:5: GTK may only be used from the main thread
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at library/core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace: <omitted, included below>
thread caused non-unwinding panic. aborting.
thread 'test_e2e_flow' panicked at tests/ui_integration.rs:93:24:

The remaining 50% of the time I have several back and forth calls with the UI and the test completes successfully.

Reproduction

I can't provide this at this time, hoping the stack trace is enough..

Expected behavior

Should be able to consistently run tauri as a subprocess without encountering GTK main thread issues.

Full tauri info output

Note this is running in a docker container, `FROM rust:1` as base image

[✔] Environment
    - OS: Debian 12.0.0 aarch64 (X64)
    ✔ webkit2gtk-4.1: 2.44.3
    ✔ rsvg2: 2.54.7
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: 1.81.0-aarch64-unknown-linux-gnu (default)
    - node: 20.11.1
    - yarn: 4.5.0
    - npm: 10.2.4

[-] Packages
    - tauri 🦀: 2.0.2
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli : 2.0.2

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.0.1
    - @tauri-apps/plugin-dialog : not installed!
    - tauri-plugin-fs 🦀: 2.0.1
    - @tauri-apps/plugin-fs : not installed!

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ./tests/ui/dist/browser
    - devUrl: http://localhost:1420/

Stack trace

0:     0xaaaadbbc6a5c - std::backtrace_rs::backtrace::libunwind::trace::h478edc47103e3f06
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0xaaaadbbc6a5c - std::backtrace_rs::backtrace::trace_unsynchronized::h42581fa4d7d2711f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0xaaaadbbc6a5c - std::sys::backtrace::_print_fmt::hfa792f5d727892f7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:     0xaaaadbbc6a5c - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hd1bd86f9e87f2dc6
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:     0xaaaadbbf0680 - core::fmt::rt::Argument::fmt::h4994c882fc039333
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:     0xaaaadbbf0680 - core::fmt::write::hf784ddce2439beb2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:     0xaaaadbbc3264 - std::io::Write::write_fmt::h3a532ab2ed2a81ef
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:     0xaaaadbbc81ec - std::sys::backtrace::BacktraceLock::print::h3dc3d1eeb242dea4
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:     0xaaaadbbc81ec - std::panicking::default_hook::{{closure}}::hdf566474624f0305
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:     0xaaaadbbc7dcc - std::panicking::default_hook::h7eca74c8246bec15
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:     0xaaaadbbc8804 - std::panicking::rust_panic_with_hook::h23f33ab5bab293ef
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:800:13
  11:     0xaaaadbbc85e4 - std::panicking::begin_panic_handler::{{closure}}::h8ea86e6103cb361c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:667:13
  12:     0xaaaadbbc6f44 - std::sys::backtrace::__rust_end_short_backtrace::h6e01bce97227982e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:168:18
  13:     0xaaaadbbc82dc - rust_begin_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
  14:     0xaaaad9bec248 - core::panicking::panic_nounwind_fmt::runtime::h38472b51f7eca294
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:112:18
  15:     0xaaaad9bec248 - core::panicking::panic_nounwind_fmt::h01b437f4a97f4346
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:122:5
  16:     0xaaaad9bec2c0 - core::panicking::panic_nounwind::h17298cd3cbc2905e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:221:5
  17:     0xaaaad9bec438 - core::panicking::panic_cannot_unwind::hd0e9c6802cc1dd3d
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:309:5
  18:     0xaaaadadaf4a8 - glib::main_context::<impl glib::auto::main_context::MainContext>::invoke_unsafe::trampoline::h924837b279df0a4a
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:119:9
  19:     0xffff9b2f89a8 - g_main_context_invoke_full
  20:     0xaaaadadaa16c - glib::main_context::<impl glib::auto::main_context::MainContext>::invoke_unsafe::ha27d78e2496bdbd4
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:131:9
  21:     0xaaaadadaa190 - glib::main_context::<impl glib::auto::main_context::MainContext>::invoke_with_priority::h55818d26747a4a03
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:62:13
  22:     0xaaaadadaa1b8 - glib::main_context::<impl glib::auto::main_context::MainContext>::invoke::h71dc06bea296114e
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:46:9
  23:     0xaaaadad96c28 - <wry::web_context::WebContext as wry::webkitgtk::web_context::WebContextExt>::register_uri_scheme::{{closure}}::{{closure}}::h3a4bc2028be129b0
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.44.1/src/webkitgtk/web_context.rs:230:13
  24:     0xaaaadad90308 - core::ops::function::FnOnce::call_once{{vtable.shim}}::he2cb23c242f68a93
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  25:     0xaaaad9c85ac0 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6f6ecd4c34f721fd
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  26:     0xaaaad9f527bc - wry::RequestAsyncResponder::respond::h899d42cfce39072a
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.44.1/src/lib.rs:291:5
  27:     0xaaaad9c92f74 - tauri_runtime_wry::create_webview::{{closure}}::{{closure}}::h4dfa18eff92ae7c3
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-runtime-wry-2.0.1/src/lib.rs:4234:36
  28:     0xaaaada018050 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0e9af0a66a742fa2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  29:     0xaaaad9c85600 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h48af8f01cd718c18
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  30:     0xaaaad9f63de4 - tauri::app::UriSchemeResponder::respond::ha08fc23069b4b7c9
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/app.rs:2013:5
  31:     0xaaaad9cb1d98 - tauri::ipc::protocol::get::{{closure}}::{{closure}}::h2b1d7bb5d8fd3384
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/ipc/protocol.rs:59:7
  32:     0xaaaad9cb2400 - tauri::ipc::protocol::get::{{closure}}::{{closure}}::hfc4fd0ae91bd909f
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/ipc/protocol.rs:142:19
  33:     0xaaaada0194a0 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h71553b866542fc3b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  34:     0xaaaad9c85c54 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7fe0f16bf78c8eb2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  35:     0xaaaad9cd2d70 - tauri::webview::Webview<R>::on_message::{{closure}}::hd1d92394c2adbb04
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/webview/mod.rs:1167:11
  36:     0xaaaada018698 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2d06c4ba0d94cca0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  37:     0xaaaad9c85c54 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7fe0f16bf78c8eb2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  38:     0xaaaad9e19878 - tauri::ipc::InvokeResolver<R>::return_result::hda1aa4121cbecd70
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/ipc/mod.rs:446:5
  39:     0xaaaad9e21434 - tauri::ipc::InvokeResolver<R>::respond_async_serialized::{{closure}}::h262c20e7ef7f0718
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.2/src/ipc/mod.rs:341:7
  40:     0xaaaada238c6c - <core::pin::Pin<P> as core::future::future::Future>::poll::h130f7e68cb718e3f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/future/future.rs:123:9
  41:     0xaaaada72a408 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::h27f9892f9140770c
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/core.rs:331:17
  42:     0xaaaada71aa48 - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::h17b4523baa2b3d6f
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/loom/std/unsafe_cell.rs:16:9
  43:     0xaaaada71aa48 - tokio::runtime::task::core::Core<T,S>::poll::h74a2d4160f6d95bb
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/core.rs:320:13
  44:     0xaaaada591f08 - tokio::runtime::task::harness::poll_future::{{closure}}::h9040d72348f35266
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:500:19
  45:     0xaaaada67f180 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h499cc00ce9ec9ca6
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  46:     0xaaaada2d7ef4 - std::panicking::try::do_call::h1d13990be54fd54f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  47:     0xaaaada3b0888 - __rust_try
  48:     0xaaaada39aefc - std::panicking::try::hce1604c00a589bb8
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  49:     0xaaaada39aefc - std::panic::catch_unwind::hc087e50050f582af
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  50:     0xaaaada564c7c - tokio::runtime::task::harness::poll_future::h5400b09f01830558
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:488:18
  51:     0xaaaada5b9008 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::hb31588573067039c
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:209:27
  52:     0xaaaada5f8b84 - tokio::runtime::task::harness::Harness<T,S>::poll::h08e171ed7564d1d4
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:154:15
  53:     0xaaaada2510d8 - tokio::runtime::task::raw::poll::h18b51efae72bae68
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/raw.rs:271:5
  54:     0xaaaadba48cb0 - tokio::runtime::task::raw::RawTask::poll::h17521fc95a782035
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/raw.rs:201:18
  55:     0xaaaadba80a38 - tokio::runtime::task::LocalNotified<S>::run::h3f52ebd7cb4fd4f4
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/mod.rs:436:9
  56:     0xaaaadba39798 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}::hcfb1e34054107e99
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:598:13
  57:     0xaaaadba39688 - tokio::runtime::coop::with_budget::h0561bdbb03435261
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:107:5
  58:     0xaaaadba39688 - tokio::runtime::coop::budget::h348e54dae9d8acb5
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:73:5
  59:     0xaaaadba39688 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::hd96e61792d3afba0
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:597:9
  60:     0xaaaadba38fe8 - tokio::runtime::scheduler::multi_thread::worker::Context::run::hef252ca50b11f9b7
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:548:24
  61:     0xaaaadba38d0c - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}::ha8cb13efabcf354d
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:513:21
  62:     0xaaaadba64e44 - tokio::runtime::context::scoped::Scoped<T>::set::hdf3801f6aae477e8
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/scoped.rs:40:9
  63:     0xaaaadba2b368 - tokio::runtime::context::set_scheduler::{{closure}}::hd9bf80ea82aa83be
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context.rs:180:26
  64:     0xaaaadba2924c - std::thread::local::LocalKey<T>::try_with::h691868da9c106ee5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:283:12
  65:     0xaaaadba2882c - std::thread::local::LocalKey<T>::with::h836960cb5a6a7316
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:260:9
  66:     0xaaaadba2b2b8 - tokio::runtime::context::set_scheduler::h0ec651188e2e1c9d
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context.rs:180:9
  67:     0xaaaadba38c38 - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::h440ef8f7da270eec
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:508:9
  68:     0xaaaadba2adf4 - tokio::runtime::context::runtime::enter_runtime::h132185df5cf26472
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/runtime.rs:65:16
  69:     0xaaaadba38a94 - tokio::runtime::scheduler::multi_thread::worker::run::h0e31eb4f2f514c78
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:500:5
  70:     0xaaaadba38858 - tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}::h20019785e8ac825a
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/worker.rs:466:45
  71:     0xaaaadba788b4 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::hc1837d70897c95c5
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/blocking/task.rs:42:21
  72:     0xaaaadba1c018 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::hd94b1a1bc27db7d4
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/core.rs:331:17
  73:     0xaaaadba1bb68 - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::h2899ac2d85ad035a
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/loom/std/unsafe_cell.rs:16:9
  74:     0xaaaadba1bb68 - tokio::runtime::task::core::Core<T,S>::poll::hbf4dd30949565cb6
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/core.rs:320:13
  75:     0xaaaadba07fac - tokio::runtime::task::harness::poll_future::{{closure}}::h377c7e968afe0e14
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:500:19
  76:     0xaaaadba44020 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h7051863ab8255c7b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  77:     0xaaaadba7cf5c - std::panicking::try::do_call::hd78617351e239c9f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  78:     0xaaaadba7c3a8 - __rust_try
  79:     0xaaaadba793dc - std::panicking::try::h36e7864564b43eb6
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  80:     0xaaaadba793dc - std::panic::catch_unwind::h71b15dbf2e397d81
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  81:     0xaaaadba07828 - tokio::runtime::task::harness::poll_future::h80a90a4c8feda5c5
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:488:18
  82:     0xaaaadba05c78 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::h821da81a98b63818
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:209:27
  83:     0xaaaadba0563c - tokio::runtime::task::harness::Harness<T,S>::poll::hb9c49b4649c58cb3
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/harness.rs:154:15
  84:     0xaaaadba49058 - tokio::runtime::task::raw::poll::hcabe394f6dc153d3
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/raw.rs:271:5
  85:     0xaaaadba48cb0 - tokio::runtime::task::raw::RawTask::poll::h17521fc95a782035
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/raw.rs:201:18
  86:     0xaaaadba80af4 - tokio::runtime::task::UnownedTask<S>::run::h35b6b6899222635d
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/task/mod.rs:473:9
  87:     0xaaaadba40a1c - tokio::runtime::blocking::pool::Task::run::hdde6c65248e83a63
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/blocking/pool.rs:160:9
  88:     0xaaaadba42ca4 - tokio::runtime::blocking::pool::Inner::run::h3ba8a8a97694f517
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/blocking/pool.rs:518:17
  89:     0xaaaadba42a00 - tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}::h3dd954ef8b064143
                               at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/blocking/pool.rs:476:13
  90:     0xaaaadba70600 - std::sys::backtrace::__rust_begin_short_backtrace::hcf735f2b42a0334f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:152:18
  91:     0xaaaadba4c670 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::hd66d6db342e285c8
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:538:17
  92:     0xaaaadba43f9c - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h6555c8b0cfa6b09e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  93:     0xaaaadba7c908 - std::panicking::try::do_call::h28108af530d59512
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  94:     0xaaaadba58ec0 - __rust_try
  95:     0xaaaadba4c1e0 - std::panicking::try::h68eb51195ad5e2ae
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  96:     0xaaaadba4c1e0 - std::panic::catch_unwind::h2c7b86bf64b9e8bf
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  97:     0xaaaadba4c1e0 - std::thread::Builder::spawn_unchecked_::{{closure}}::h50c91450da0b77f2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:537:30
  98:     0xaaaadba4cc20 - core::ops::function::FnOnce::call_once{{vtable.shim}}::heddd06d825ea0e6b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  99:     0xaaaadbbcd750 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h05310b62d542d3c5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
 100:     0xaaaadbbcd750 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbe429aac7e445852
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
 101:     0xaaaadbbcd750 - std::sys::pal::unix::thread::Thread::new::thread_start::h313f0bba9fe0bc05
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/pal/unix/thread.rs:108:17
 102:     0xffff990cee30 - <unknown>
 103:     0xffff99137adc - <unknown>
 104:                0x0 - <unknown>

Additional context

No response

@zakhenry zakhenry added status: needs triage This issue needs to triage, applied to new issues type: bug labels Oct 10, 2024
@FabianLars
Copy link
Member

Hmm, not sure if the stacktrace alone is enough tbh (it's not for me, but maybe for someone here who can actually read those lol).

In the spawned tauri app, are you spawning your own tokio runtime (maybe via #[tokio::main]) or use std threads?

btw, i assume tokio::process::spawn is talking about the Command's spawn method?

@zakhenry
Copy link
Author

Sorry yes I mean the spawn method of tokio::process::Command, and yep my own tokio runtime as

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let config = CliArguments::parse().try_into()?;

    tauri::async_runtime::set(tokio::runtime::Handle::current());

    // run my tauri app and a bunch of other things with tokio
}

@altunenes
Copy link

I got a similar error in a similar one (macos v 13.2). But interestingly, the error does not appear on other macOS (v 15 & v 14). I mean I tried the app with 6 different Macs and the error only appeared only one machine. I don't have an idea how can I reproduce the error though :(

tokio-runtime-worker exc bad aacess (SIGSEGV)

@FabioGNR
Copy link

FabioGNR commented Oct 21, 2024

Just adding some information that it doesn't seem to depend on custom tokio runtimes.

I am consistently getting this error in my app on launch. It's not spawning a runtime manually, and disabling any thread::spawn calls didn't seem to help.

Then I created a test app using npm create tauri-app@latest (vanilla typescript frontend) and changed the .run() to a loop with .run_iteration(). The first time I launched that I got the same error (cargo tauri dev), but since then I haven't been able to reproduce.

If I find a small consistent repro I will share it.

edit: platform is Linux (Ubuntu 24.10) by the way.

@FabioGNR
Copy link

For me the following small application based on the template triggers it approximately 50% of the time:
https://github.com/FabioGNR/tauri-issue-11312

I am running it as cargo tauri dev. The crash should happen within 5 seconds of it compiling the target, if not, just run cargo tauri dev again.

@zakhenry
Copy link
Author

@FabioGNR amazing that is a nice small repro thanks, are you able to share the stack trace so I can see if it matches mine (i.e. likely same root cause). I'm on macos so won't encounter the same issue unless I try set it up with docker I guess.

fwiw I'm also executing the app with app.run_iteration inside a loop, although slight difference for me is that rather than a thread sleep I'm doing a task::yield_now().await, but it could certainly be related.

@eldoccc
Copy link

eldoccc commented Oct 25, 2024

I'm also doing an app.run_iteration but instead of doing a sleep or a task::yield_now().await I'm doing gtk::main_iteration_do(true) . It also but crash on launch with a similar stack trace.

The tauri app is spawned in a tokio::task and I've made sure to call any_thread() on the Builder

@FabioGNR
Copy link

@zakhenry of course, here's the stacktrace:
stacktrace.txt

@zakhenry
Copy link
Author

Thanks @FabioGNR yep the two stacktraces look the same at a certain point (from register_uri_scheme onwards) so I think it's a solid repro for my case too

@eldoccc
Copy link

eldoccc commented Oct 28, 2024

I don't know if this crash could happend for different reasons since you crash in tauri 2.0.2, but my app works fine in 2.0.3.
It starts crashing in 2.0.4

@eldoccc
Copy link

eldoccc commented Nov 14, 2024

tried to update to 2.1 and got the error. I still gotta use 2.0.3.

Could this problem be linked to 3cb73d0 ?

@eldoccc
Copy link

eldoccc commented Dec 11, 2024

@zakhenry @FabioGNR has any of you managed to fix the error on your side by any chance ?

@FabioGNR
Copy link

No, I reverted back to a working version 2.0.0-rc and haven't tried since. I'll share an update if I found something.

@FabioGNR
Copy link

FabioGNR commented Dec 15, 2024

Took another look at this, the call to GTK is done from the MainContext thread, so that's not the issue. But it appears gtk::init() has not always been called on the main thread yet.

tao uses gtk_application_new which should remove the need to call gtk::init(), but as mentioned here:
https://docs.gtk.org/gtk3/ctor.Application.new.html
This is done in the startup handler so I'm guessing there's a possible race condition.

Adding a call to gtk::init() before calling gtk::Application::new() seems to workaround this issue.
(in tao: src/platform_impl/linux/event_loop.rs/new_gtk, example https://github.com/tauri-apps/tao/compare/v0.30...FabioGNR:tao:gtk-init?expand=1)
You can do that as a workaround by patching tao in your cargo.toml, but it's probably not the way to go for actually deploying something.

@zakhenry
Copy link
Author

@FabioGNR this seems very promising and might be worth raising the PR anyway? If I'm interpreting you correctly the call `tao`` makes to initialise GTK does not actually eagerly call gtk::init(), but lazily calls it later when gtk is subsequently interacted with, and for some cases this call might not be coming from the main thread, causing this issue?

If that is right then in seems pretty sensible to ensure it is called from the main thread before calling gtk::Application::new()

@FabioGNR
Copy link

FabioGNR commented Dec 17, 2024

but lazily calls it later when gtk is subsequently interacted with

Having looked further into it, the call to gtk_init() should be done when calling g_application_register. In tao this is done a few lines after gtk::Application::new(), app.register(cancellable)?;. The register call should send the startup signal, and gtk-rs installs a signal handler which will mark the thread as initialized (afterwards calling gtk::init() turns into a no-op). I'm guessing the real default gtk startup handler does not call gtk_init under the hood in this situation. It doesn't seem like a lazy init or race condition knowing this.

If I understand correctly gtk signals first call the custom handlers and then the default, which would mean it's marked as initialized before it actually is. Still, this shouldn't affect calls to gtk_init I believe.

Either way I'm stuck at this point because I'm having trouble debugging the internal of gtk-rs and gtk itself.
I'll create a PR to add the gtk::init() call as a workaround, though it would be nice to know exactly why this happens, and why it only started recently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants