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

[v0.74] Android: Promises from native modules stuck #44555

Open
birdofpreyru opened this issue May 13, 2024 · 6 comments
Open

[v0.74] Android: Promises from native modules stuck #44555

birdofpreyru opened this issue May 13, 2024 · 6 comments
Labels
Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Version Info Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@birdofpreyru
Copy link
Contributor

birdofpreyru commented May 13, 2024

Description

Hey, I am upgrading an existing app from RN v0.73.6 to v0.74.1, trying to make it work for Android, new architecture, bridge-less (and the app was working fine on RN v0.73 with new arch, and bridge; I haven't tested bridge-less before).

I've encountered an issue that shortly after running the app promises from native modules stuck to resolve or reject. I.e. in my code I have some function, say doSmth(): Promise<void> (which is a TS-side definition for a native function in a native module) that is called repeatedly, does some work on the native side, then does promise.resolve(null) on the native side, to resolve the pending promise on the TS side. It works for me fine at first, but after some call the promise from doSmth() just stuck indefinitely without either resolve or reject.

I've added console logging both at native and TS side, so I see that promise.resolve(null) is called at native side for that pending promise (i.e. I see console log from the line just before it); the call to promise.resolve(null) does not fail (I have the native block of code wrapped into try/catch, and a log statement in catch does not print); but on the TS side that promise stays pending (again, if I haven't miss anything, on TS side I have console statements just before the promise, after awaiting it, and I have entire block wrapped into try/catch with another console statement; and it nor statement after awaiting, nor in the catch prints).

So... I am still trying to further dig into it, but already creating the ticket, just in case somebody has seen something similar, or has some helpful ideas / insights.

P.S.: In my current understanding, smth happens in C++ code implementation of promise resolution; and as of now I have no idea how to debug that in an RN app 😬 Ideally, I guess, I want to stick debugger breakpoint here in C++ code, to see what happens, but how? If in Android Studio I set breakpoints into C++ code of RN they do not seem to have effect :(

And I have confirmed that my app works seemingly fine with v0.74.1 if I disable bridge-less mode.

Steps to reproduce

N/A

React Native Version

N/A

Affected Platforms

Runtime - Android

Areas

Other (please specify)

Output of npx react-native info

N/A

Stacktrace or Logs

N/A

Reproducer

N/A

Screenshots and Videos

No response

@birdofpreyru birdofpreyru added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels May 13, 2024
Copy link

⚠️ Add or Reformat Version Info
ℹ️ We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Triage 🔍 labels May 13, 2024
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@github-actions github-actions bot added the Platform: Android Android applications. label May 13, 2024
@birdofpreyru
Copy link
Contributor Author

birdofpreyru commented May 13, 2024

Hey @cortinico , any thoughts about this one? I am not sure what can I do — I can't get Android Studio debugger to work on C++ RN code; I don't see any apparent issues with my code on TS & Java side; and although the issue reliably happens shortly after the app start-up, it is not in an deterministic way, sometimes I get it sooner, sometimes later.

It feels like perhaps some dependency in the app, not correctly migrated to the new arch, does something wrong with communications to the native layer, and somehow rapidly exhaust the ability of bridgleless communication to handle new callbacks / promises... but I don't see anything in adb logcat logs, or app behavior hinting on where to look for the problem (though my first guess would be react-native-webview, or @react-native-firebase to blame — both poorly maintained, and using some weird patterns in their code, which I haven't seen in RN docs).

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels May 13, 2024
@cortinico
Copy link
Contributor

Hey @cortinico , any thoughts about this one?

I'd say, let's start by attaching a reproducer to this issue. This week we're all busy with ReactConf so we won't be able to take a look at it

@birdofpreyru
Copy link
Contributor Author

This week we're all busy with ReactConf

I hope, ReactConf was fun :)

Regarding my issue — following the trial-and-error approach, I tried to comment out different parts of my app relying on different 3rd party libraries, and narrowed it down to react-native-google-mobile-ads — if I don't use any functionality from it, my app works fine. Though, while I was testing that library got some fixes... thus, I am still to try whether the problem is there with v13.3.1 of that library, and if so, what might be causing it.

@cortinico cortinico removed the Needs: Attention Issues where the author has responded to feedback. label May 20, 2024
@birdofpreyru
Copy link
Contributor Author

@cortinico I have narrowed it down to the issue still happening with react-native-google-mobile-ads v13.3.0, and the issue not present after it upgrade to v13.3.1 and above. The only code change between these versions seems to be a change in event name: invertase/react-native-google-mobile-ads@v13.3.0...v13.3.1
image

I am not sure why that event name was changed, and how may it affect unrelated promises not being resolved in the bridgeless mode. Though, if it makes any sense, I'd say RN misses to detect some problem here, and warn about it, or probably throw a hard error.

birdofpreyru referenced this issue in invertase/react-native-google-mobile-ads May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Version Info Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

2 participants