wry icon indicating copy to clipboard operation
wry copied to clipboard

Android BorrowError panic in wry and inability to restart/launch

Open tristan-morris opened this issue 1 year ago • 19 comments
trafficstars

Describe the bug I'm attempting to run Tauri on an existing prod React project. I have been encountering a panic somewhat reliably after a deep-link is called (user goes to complete oauth flow, deep-link drops them back in the app successfully - this works great). However, on next app launch it seems like the deep-link state is still present and causes a panic. This panic is then irrecoverable. Force-quit the tauri app = panic. Try and force-quit again and panic. App is then dead mostly. Sometimes it will come back, as if a bad event has been dispatched successfully. Delete the app from the device and it can be reliably installed.

I have been able to cause the same set of panics with a similar flow - when there's competition for launching the WebKitClient(?).

I haven't made much more progress on this issue but happy to keep looking into it.

Steps To Reproduce

  • Install Tauri
  • Install deep-link plugin (may not entirely be necessary - I've caused it other ways but this seems semi reliable)
  • Configure a deep link
  • Trigger a deep-link to arrive back in app
  • Close the app (kill)
  • Re-launch the app.

Expected behavior No panic.

Screenshots Panic: image

References: image

Platform and Versions (please complete the following information): OS: Android on Pixel 4a 5G. I am port forwarding from the Android device to my dev PC. Rustc: 1.82

Additional context

Logcat Output during the panic (nothing useful beyond the reference to unwinding panic):

...snip...
11-17 08:26:34.924 18908 18908 F DEBUG   :       #08 pc 00000000015c3db8  /data/app/~~XWb8Z89T6mNxIkk6s7bm2A==/io.testy.ui-7cAR2kQUjsQd7GVdttgacA==/base.apk (offset 0x5e8000) (core::panicking::panic_cannot_unwind::he22847d5ac2210b8+20)
11-17 08:26:34.924 18908 18908 F DEBUG   :       #09 pc 0000000000a1c4d8  /data/app/~~XWb8Z89T6mNxIkk6s7bm2A==/io.testy.ui-7cAR2kQUjsQd7GVdttgacA==/base.apk (offset 0x5e8000) (Java_io_testy_ui_RustWebViewClient_withAssetLoader+36)
11-17 08:26:34.924 18908 18908 F DEBUG   :       #10 pc 0000000000384370  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: 3f7d5a016e08d528f129bdd336d81168)

Full Logcat output: https://gist.github.com/tristan-morris/44dd5f7e451f6f81d260c7a56b14afa4

$ cargo tauri info

[✔] Environment - OS: Ubuntu 23.4.0 x86_64 (X64) ✔ webkit2gtk-4.1: 2.42.4 ✔ rsvg2: 2.54.5 ✔ rustc: 1.82.0 (f6e511eec 2024-10-15) ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21) ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24) ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN) - node: 21.5.0 - yarn: 1.22.21 - npm: 10.2.4

[-] Packages - tauri 🦀: 2.1.1 - tauri-build 🦀: 2.0.3 - wry 🦀: 0.47.0 - tao 🦀: 0.30.8 - tauri-cli 🦀: 2.1.0 - @tauri-apps/api : 2.1.1 - @tauri-apps/cli : 2.1.0

[-] Plugins - tauri-plugin-log 🦀: 2.0.2 - @tauri-apps/plugin-log : not installed! - tauri-plugin-notification 🦀: 2.0.1 - @tauri-apps/plugin-notification : 2.0.0 - tauri-plugin-shell 🦀: 2.0.2 - @tauri-apps/plugin-shell : 2.0.1 - tauri-plugin-geolocation 🦀: 2.0.1 - @tauri-apps/plugin-geolocation : 2.0.0 - tauri-plugin-deep-link 🦀: 2.0.1 - @tauri-apps/plugin-deep-link : 2.0.0 - tauri-plugin-fs 🦀: 2.0.3 - @tauri-apps/plugin-fs : 2.0.2

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

tristan-morris avatar Nov 18 '24 03:11 tristan-morris

I'm getting a similar error. I'm using MapLibre GL JS in tauri on android and occasionally while zooming/panning around in the map I get a crash:

11-18 16:02:05.774 28302 28340 I RustStdoutStderr: thread '<unnamed>' panicked at /home/nic96/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.47.1/src/android/binding.rs:109:42:
11-18 16:02:05.774 28302 28340 I RustStdoutStderr: already mutably borrowed: BorrowError
11-18 16:02:05.774 28302 28340 I RustStdoutStderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
11-18 16:02:05.775 28302 28340 I RustStdoutStderr: thread '<unnamed>' panicked at /home/nic96/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.47.1/src/android/binding.rs:109:42:
11-18 16:02:05.775 28302 28340 I RustStdoutStderr: already mutably borrowed: BorrowError
11-18 16:02:05.776 28302 28340 I RustStdoutStderr: thread '<unnamed>' panicked at library/core/src/panicking.rs:221:5:
11-18 16:02:05.776 28302 28340 I RustStdoutStderr: panic in a function that cannot unwind
11-18 16:02:05.776 28302 28340 I RustStdoutStderr: stack backtrace:
...

nic96 avatar Nov 18 '24 23:11 nic96

Interesting! Thanks for the report as it helped confirm my sanity.

I'm using Mapbox Gl Js so it could relate somehow. As a counter point, I haven't had any crashes (past hour or two) when dev'ing on my Mac M1, but my much more performant PC panics.

tristan-morris avatar Nov 18 '24 23:11 tristan-morris

This is probably related to: https://github.com/tauri-apps/wry/issues/1379

tdomhan avatar Dec 28 '24 17:12 tdomhan

Thanks for confirming! I moved to capacitorjs after making no progress.

tristan-morris avatar Dec 28 '24 18:12 tristan-morris

I have the same issue, the first launch work, but an app relaunch randomly crash.

This is my logs : Tauri-crash.log

Maxou44 avatar Jan 04 '25 17:01 Maxou44

We are encountering this exact same issue.

tracy-codes avatar Jan 23 '25 22:01 tracy-codes

When in dev mode, the app will open successfully only once every 5 times, and the remaining 4 times will crash due to this reason

hongfanmeng avatar Jan 30 '25 04:01 hongfanmeng

Does anyone know how to fix this bug? It's blocking me from building an Android app using Tauri. 😰

Maxou44 avatar Jan 30 '25 09:01 Maxou44

Downgrading the wry version to 0.46.1 appears to resolve the bug. Below is the updated Cargo.toml file

[dependencies]
tauri = { version = "=2.0.6", features = [] }
tauri-runtime-wry = "=2.1.2"
tauri-runtime = "=2.1.1"

hongfanmeng avatar Jan 31 '25 00:01 hongfanmeng

doesn't work for me with latest tauri version. ( I won't downgrade )

alexiokay avatar Feb 27 '25 14:02 alexiokay

Any ETA on this ? My app is crashing on production for Android users because of this issue. My Play Console reports dozens of crashes every hour for this specific issue (it's always the same error and logs).

Vexcited avatar Mar 15 '25 21:03 Vexcited

No ETA. Some reproduction examples/steps, or at least some kind of descriptions on where/when this happens in your app would probably help. Afaik we haven't been able to reproduce this in latest tauri/wry anymore (iirc https://github.com/tauri-apps/wry/pull/1505) but not sure (i don't have a working dev env until next week or so, so can't confirm myself - not that i was ever able to repro it lol)

FabianLars avatar Mar 15 '25 22:03 FabianLars

I am running on wry 0.49, I'll try to bump to latest to have this fix and will tell if it fixed the issue for me or not! If you want more details, I have an FCM service running for push notifications on Android and that's all. When I did not have it, it did not crash. Thanks for the quick response, will try it out !

Vexcited avatar Mar 15 '25 22:03 Vexcited

Is it possible this is related to this bug https://github.com/tauri-apps/wry/issues/1379 ?

tdomhan avatar Mar 16 '25 08:03 tdomhan

I had the same issue.

In dev mode, if I do not close the Android app, just use Ctrl+C to interrupt debugging on PC, and then re-execute tauri android dev, there is a high probability that this problem will occur.

thread '<unnamed>' panicked at D:\path\to\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\wry-0.48.1\src\android\binding.rs:109:42:
already mutably borrowed: BorrowError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

thread '<unnamed>' panicked at library/core/src/panicking.rs:218:5:
panic in a function that cannot unwind

caipeter888 avatar Mar 17 '25 15:03 caipeter888

that's also an outdated wry version (0.48) so basically irrelevant until someone sees it on 0.50.x as well

FabianLars avatar Mar 17 '25 20:03 FabianLars

I can say I am probably facing the same issue, but without even using the deep-link plugin.

Basically, my app only starts once after it's installed; for any subsequent steps it hangs indefinitely until an ANR popup appears.

The app in question is https://github.com/NyaomiDEV/Ampersand. The error happens on both builds produced by GH Actions as well as local builds.

NyaomiDEV avatar Mar 18 '25 10:03 NyaomiDEV

Afaik we haven't been able to reproduce this in latest tauri/wry anymore (iirc #1505) but not sure (i don't have a working dev env until next week or so, so can't confirm myself - not that i was ever able to repro it lol)

wry 0.50 definitely fixed the issue for me, I'm back to 0% crash in the Play Console reports and I'm not getting anymore crash in development neither ! Thanks you !

Vexcited avatar Mar 18 '25 21:03 Vexcited

I'm running under 0.50.5, see https://github.com/Vexcited/StayReal/blob/39026d86fa7e487bb94f7dc8e3d9d9704805e663/src-tauri/Cargo.toml#L31-L32

I have a small patch for the Kotlin code because my app needs to do some tweaks about HTTP requests...

Vexcited avatar Mar 19 '25 15:03 Vexcited

Updated from 0.48.1 to 0.50.5 and the error was gone.

TheLexoPlexx avatar Apr 14 '25 07:04 TheLexoPlexx