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] Direct Plugin calls from rust result in crashes in android #13063

Open
F8RZD opened this issue Mar 24, 2025 · 5 comments
Open

[bug] Direct Plugin calls from rust result in crashes in android #13063

F8RZD opened this issue Mar 24, 2025 · 5 comments
Labels
platform: Android status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@F8RZD
Copy link

F8RZD commented Mar 24, 2025

Describe the bug

Calling plugins from rust backend crashes the app in android

sample:

let payload = PingRequest {
    value: Some("Hello Ping".into()),
};
app.kt_runtime().ping(payload);

All I see in logs is

03-24 08:47:04.772  7341  7352 I .farzad.toolkit: Thread[2,tid=7352,WaitingInMainSignalCatcherLoop,Thread*=0x72c047b38b20,peer=0x14001620,"Signal Catcher"]: reacting to signal 3
03-24 08:47:04.772  7341  7352 I .farzad.toolkit:
03-24 08:47:05.104  7341  7352 I .farzad.toolkit: Wrote stack traces to tombstoned

And the App isn't working pop up in my emulator.

The same code works fine in desktop and also works fine if I call it from frontend instead of rust.

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Arch Linux Rolling Release x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.48.0
    ✔ rsvg2: 2.60.0
    ✔ rustc: 1.85.1 (4eb161250 2025-03-15)
    ✔ cargo: 1.85.1 (d73d2caf9 2024-12-31)
    ✔ rustup: 1.28.1 (2025-03-05)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (overridden by environment variable RUSTUP_TOOLCHAIN)
    - node: 20.18.3
    - yarn: 1.22.22
    - npm: 11.2.0
    - bun: 1.2.5

[-] Packages
    - tauri 🦀: 2.2.3
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.1
    - tao 🦀: 0.31.1
    - tauri-cli 🦀: 2.1.0

[-] Plugins
    - tauri-plugin-single-instance 🦀: 2.2.1
    - tauri-plugin-updater 🦀: 2.3.1
    - tauri-plugin-shell 🦀: 2.2.0
    - tauri-plugin-dialog 🦀: 2.2.0
    - tauri-plugin-fs 🦀: 2.2.0
    - tauri-plugin-os 🦀: 2.2.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist

Stack trace


Additional context

No response

@F8RZD F8RZD added status: needs triage This issue needs to triage, applied to new issues type: bug labels Mar 24, 2025
@FabianLars
Copy link
Member

Can you try making that call in an async context (or in another thread)? It may also help to upgrade tauri idk

We use this approach in a few of our official plugins as well without issues so if the above doesn't help i'm afraid we'll need a full (minimal) reproduction repo to look at.

@F8RZD
Copy link
Author

F8RZD commented Apr 4, 2025

@FabianLars

Here's a full example https://github.com/F8RZD/tauri-kotlin-problem/tree/main/tauri-plugin-kt-runtime.

Failing code:

// This is working code but requires frontend to execute so is not suitable for my example
// let _ = handle.emit("sms-relay", sms_payload.clone());

// This code crashes the app
let _ = handle.kt_runtime().send_sms(sms_payload.clone());

https://github.com/F8RZD/tauri-kotlin-problem/blob/5b2b69393cd6324cd69e6c35989b872d6e934062/tauri-plugin-kt-runtime/examples/vanilla/src-tauri/src/lib.rs#L22C1-L27C67

The plugin is meant to provide background SMS forwarding capabilities

@F8RZD
Copy link
Author

F8RZD commented Apr 4, 2025

The code triggers when a new SMS is received on emulator

@F8RZD
Copy link
Author

F8RZD commented Apr 5, 2025

Can you try making that call in an async context (or in another thread)? It may also help to upgrade tauri idk

I completely missed the point about trying async context. it fixed the crashing issue.
I'll let the issue stay open just in case you might want to add this detail to future docs.

@F8RZD
Copy link
Author

F8RZD commented Apr 5, 2025

There still remains a major issue with using tauri for background applications.

If the app is closed from recent apps inside avd this line of code freezes the app.

let res = self.0.run_mobile_plugin::<()>("send_sms", payload);

It stays frozen until the app is reopened and all calls fail at the same time with this error message:

04-05 08:49:34.873  3801  4239 I RustStdoutStderr: res: Err(
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:     InvokeRejected(
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:         ErrorResponse {
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:             code: None,
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:             message: Some(
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:                 "Plugin kt-runtime not initialized",
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:             ),
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:             data: (),
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:         },
04-05 08:49:34.873  3801  4239 I RustStdoutStderr:     ),
04-05 08:49:34.873  3801  4239 I RustStdoutStderr: )

Somehow this freezing is not affecting the async-runtime of tauri. maybe I'm just wrong assuming it's freezing but this long awaiting call that is most likely to fail makes the development cycle much more cumbersome.

e.g. I now have to use a mutex to determine if the task X is ran or it just timed out and will fail in future when the app opens.
I might be wrong about too many things I truly have no idea what's going on under the hood

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

No branches or pull requests

2 participants