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] custom IPC procotol on V2 beta panics if used with async commands #9794

Closed
petejohanson opened this issue May 15, 2024 · 1 comment
Closed
Labels
platform: Linux priority: 1 high status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@petejohanson
Copy link

Describe the bug

Attempting to set up a V2 beta Tauri app and use raw command request/responses fails with a panic if the command is async.

To test:

  • Used beta create-tauri-app to scaffold a basic Tauri + React project.
  • Enabled the linux-ipc-protocol feature in src-tauri/Cargo.toml for the tauri crate.
  • Updated the sample greet function and calling code to use Uint8Array on the client side, and tauri::ipc::{Request, Response} on the Rust side and UTF-8 byte arrays for the strings passed back and forth.
  • Tried with greet marked async and without.

Thanks! ❤️

Reproduction

I've created a minimal case to reproduce this at https://github.com/petejohanson/test-async-custom-protocol/

If you change the greet function declaration at https://github.com/petejohanson/test-async-custom-protocol/blob/main/src-tauri/src/main.rs#L10 to remove the async then it works as expected.

With that test case as is, at least on latest Fedora, the following produces a panic:

  • RUST_BACKTRACE=1 npm run tauri dev
  • Enter asdf into the text entry
  • Click "Greet" button.

Expected behavior

async command completes, and greeting text is returned to the web code, just like happens with non-async command.

Full tauri info output

❯ npm run tauri info

> test-async-custom-protocol@0.0.0 tauri
> tauri info


[✔] Environment
    - OS: Fedora 40 X64
    ✔ webkit2gtk-4.1: 2.44.1
    ✔ rsvg2: 2.57.1
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 18.12.0
    - npm: 8.19.2

[-] Packages
    - tauri [RUST]: 2.0.0-beta.19
    - tauri-build [RUST]: 2.0.0-beta.15
    - wry [RUST]: 0.39.5
    - tao [RUST]: 0.28.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.11
    - @tauri-apps/cli [NPM]: 2.0.0-beta.17

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: webkit2gtk::auto::uri_scheme_response::URISchemeResponse::new
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/webkit2gtk-2.0.1/src/auto/uri_scheme_response.rs:26:5
   3: wry::webkitgtk::web_context::actually_register_uri_scheme::{{closure}}::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.39.5/src/webkitgtk/web_context.rs:374:26
   4: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   5: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
   6: wry::RequestAsyncResponder::respond
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.39.5/src/lib.rs:287:5
   7: tauri_runtime_wry::create_webview::{{closure}}::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-runtime-wry-2.0.0-beta.16/src/lib.rs:3943:36
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   9: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  10: tauri::app::UriSchemeResponder::respond
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/app.rs:1760:5
  11: tauri::ipc::protocol::get::{{closure}}::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/ipc/protocol.rs:46:7
  12: tauri::ipc::protocol::get::{{closure}}::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/ipc/protocol.rs:108:19
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
  14: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  15: tauri::webview::Webview<R>::on_message::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/webview/mod.rs:1146:11
  16: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
  17: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  18: tauri::ipc::InvokeResolver<R>::return_result
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/ipc/mod.rs:419:5
  19: tauri::ipc::InvokeResolver<R>::respond_async_serialized::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.19/src/ipc/mod.rs:314:7
  20: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/core.rs:328:17
  21: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/loom/std/unsafe_cell.rs:16:9
  22: tokio::runtime::task::core::Core<T,S>::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/core.rs:317:13
  23: tokio::runtime::task::harness::poll_future::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:485:19
  24: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panic/unwind_safe.rs:272:9
  25: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  26: __rust_try
  27: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  28: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  29: tokio::runtime::task::harness::poll_future
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:473:18
  30: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:208:27
  31: tokio::runtime::task::harness::Harness<T,S>::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:153:15
  32: tokio::runtime::task::raw::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/raw.rs:271:5
  33: tokio::runtime::task::raw::RawTask::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/raw.rs:201:18
  34: tokio::runtime::task::LocalNotified<S>::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/mod.rs:427:9
  35: tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:576:13
  36: tokio::runtime::coop::with_budget
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:107:5
  37: tokio::runtime::coop::budget
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:73:5
  38: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:575:9
  39: tokio::runtime::scheduler::multi_thread::worker::Context::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:538:24
  40: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:491:21
  41: tokio::runtime::context::scoped::Scoped<T>::set
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/scoped.rs:40:9
  42: tokio::runtime::context::set_scheduler::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context.rs:176:26
  43: std::thread::local::LocalKey<T>::try_with
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/local.rs:270:16
  44: std::thread::local::LocalKey<T>::with
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/local.rs:246:9
  45: tokio::runtime::context::set_scheduler
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context.rs:176:9
  46: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:486:9
  47: tokio::runtime::context::runtime::enter_runtime
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/runtime.rs:65:16
  48: tokio::runtime::scheduler::multi_thread::worker::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:478:5
  49: tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/worker.rs:447:45
  50: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/blocking/task.rs:42:21
  51: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/core.rs:328:17
  52: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/loom/std/unsafe_cell.rs:16:9
  53: tokio::runtime::task::core::Core<T,S>::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/core.rs:317:13
  54: tokio::runtime::task::harness::poll_future::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:485:19
  55: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panic/unwind_safe.rs:272:9
  56: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  57: __rust_try
  58: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  59: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  60: tokio::runtime::task::harness::poll_future
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:473:18
  61: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:208:27
  62: tokio::runtime::task::harness::Harness<T,S>::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/harness.rs:153:15
  63: tokio::runtime::task::raw::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/raw.rs:271:5
  64: tokio::runtime::task::raw::RawTask::poll
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/raw.rs:201:18
  65: tokio::runtime::task::UnownedTask<S>::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/task/mod.rs:464:9
  66: tokio::runtime::blocking::pool::Task::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/blocking/pool.rs:159:9
  67: tokio::runtime::blocking::pool::Inner::run
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/blocking/pool.rs:513:17
  68: tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}
             at /home/peter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/blocking/pool.rs:471:13

Additional context

The stacktrace points to this key line in URISchemeResponse::new which first asserts assert_initialized_main_thread!(); which I assume is failing when async because the executor is running the command on some thread other than the main thread.

@petejohanson
Copy link
Author

Thanks! Will test this in our app and compare performance.

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

No branches or pull requests

3 participants