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

[core][Android] Fix crashes during the deallocation of shared objects #28491

Conversation

lukmccall
Copy link
Contributor

Why

Fixes crashes during the deallocation of shared objects.

2024-04-25 17:10:51.732 10991-11072 libc++abi               dev.expo.payments                    E  terminating with uncaught exception of type std::runtime_error: Unable to retrieve jni environment. Is the thread attached?
2024-04-25 17:10:51.732 10991-11072 libc                    dev.expo.payments                    A  Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 11072 (hades), pid 10991 (v.expo.payments)

How

We attached the Hades thread to the JVM to call a method. However, this approach was insufficient as the default destructor for jni::global_ref was called outside of the added thread scope. To address this issue, I modified the way the global ref is passed to the shared object native state.

Test Plan

  • NCL ✅
  • double-check if video player is deallocated correctly ✅

@lukmccall lukmccall requested a review from aleqsio April 27, 2024 10:14
@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Apr 27, 2024
@expo-bot
Copy link
Collaborator

The Pull Request introduced fingerprint changes against the base commit: 0a8c904

Fingerprint diff
[
  {
    "type": "dir",
    "filePath": "../../packages/expo-modules-core/android",
    "reasons": [
      "expoAutolinkingAndroid"
    ],
    "hash": "81744a715b858aba3f3f7191487b1bec19a00bb0"
  }
]

Generated by PR labeler 🤖

Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix: it looks like the ownership of ThreadSafeJNIGlobalRef is actually not be shared. maybe we could consider unique_ptr a little bit.

@lukmccall
Copy link
Contributor Author

nix: it looks like the ownership of ThreadSafeJNIGlobalRef is actually not be shared. maybe we could consider unique_ptr a little bit.

When capturing a unique_ptr in a std::function, the generated object loses the copy constructor, making it impossible to convert the lambda to std::function.

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@lukmccall lukmccall merged commit 849cb7d into main Apr 28, 2024
1 check passed
@lukmccall lukmccall deleted the @lukmccall/core/fix-crashes-during-deallocation-of-shared-objects branch April 28, 2024 07:59
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Apr 28, 2024
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants