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

fix(android): BorrowError crash when loading assets on Android #1505

Merged
merged 2 commits into from
Mar 2, 2025

Conversation

lucasfernog
Copy link
Member

@lucasfernog lucasfernog commented Feb 28, 2025

There is a race condition on the Android asset loading where the custom asset loading function is checked by the Java side while Rust is still setting it up, leading to a already mutably borrowed: BorrowError panic in the withAssetLoader function.
Using Mutex instead of RefCell is the safer approach. Performance impact shouldn't be relevant here, since it's only a small lookup overhead every IPC and asset loading call.

ref tauri-apps/tauri#12812

There is a race condition on the Android asset loading where the custom asset loading function is checked by the Java side while Rust is still setting it up, leading to a `already mutably borrowed: BorrowError` panic in the withAssetLoader function.
Looks like moving the function setup to happen before triggering the webview creation fixes it.
@lucasfernog lucasfernog requested a review from a team as a code owner February 28, 2025 16:56
Copy link
Contributor

github-actions bot commented Feb 28, 2025

Package Changes Through 154d52a

There are 1 changes which include wry with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
wry 0.50.1 0.50.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@lucasfernog lucasfernog marked this pull request as draft February 28, 2025 16:58
@lucasfernog
Copy link
Member Author

this is a bit difficult to reproduce, but it looks like it's not crashing anymore.

@lucasfernog
Copy link
Member Author

script i've used to verify it:

watch -n 2 'adb shell am force-stop com.tauri.api && sleep 1 && adb shell am start -a android.intent.action.MAIN -n com.tauri.api/.MainActivity'

basically reopening the app every 2 seconds to see if it loads properly

@lucasfernog lucasfernog marked this pull request as ready for review February 28, 2025 17:11
@lucasfernog
Copy link
Member Author

user reported a different crash, I'll investigate further tomorrow

@lucasfernog
Copy link
Member Author

looks like the reported crash is not related to this change (only happens in prod)

@lucasfernog lucasfernog merged commit cef818f into dev Mar 2, 2025
13 checks passed
@lucasfernog lucasfernog deleted the fix/android-borrow-panic branch March 2, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant