react-native: [v0.74] Android: Promises from native modules stuck
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (15 by maintainers)
Commits related to this issue
- fix: topNative name changed to topNativeEvent. — committed to invertase/react-native-google-mobile-ads by ugurdalkiran 3 years ago
Sounds good to me.
Hey @philIip ,
Yeap, not a blocker for me, v13.3.1 fixed it for me.
Yes, it is, thus what you wrote reads plausible.
Well… I decided to ruin my Saturday with a bit of unpaid work on my personal projects, and stuff related to them, thus here you go, a repro for this: https://github.com/birdofpreyru/issue-44555
Just run it for Android with dev server, and look at logs. By design it is supposed to keep printing the following, once each second:
And it works that way without the buggy
react-native-google-mobile-adsversion, but with it it ends with this message (that seems to be the error patched in the next version of RN Google Mobile Ads):Note,
This error message appears with RN v0.74.2 being used in the repro; I have reported the issue using RN v0.74.1 originally, and that message did not appear with that version, despite the error breaking the bridge (I mean breaking the “no-bridge” 😅 ) the same way; thus, my original experience was that promises just stopped to resolve at random without any sign of anything going wrong.
To add that Ping / Pong messaging, which waits each time for a promise from a call to native to resolve, I’ve installed a library of mine
@dr.pogodin/react-native-audio(turbo module) and addedping()function to it usingpatch-package. Done this way just to rapidly create the repro. I believe, the actual library, nor the way I patched it, do not matter here — the point is that an error in one library broke promise resolution in unrelated library. Originally, it happened without any error message. And without bridge-less mode it does not cause such disastrous effect for other modules.@birdofpreyru sorry for the delay in investigation! i got a bout of covid and the rest of the crew is busy with prepping the release. i’m working on trying to find a repro, but if anyone figures out a way to create a repo that can reproduce with specific steps, that would be awesome!
in the meantime, can you answer a few questions for me?
thanks for reporting this!!! hope we can understand what’s going on soon.
@cortinico I have narrowed it down to the issue still happening with
react-native-google-mobile-adsv13.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: https://github.com/invertase/react-native-google-mobile-ads/compare/v13.3.0...v13.3.1I 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.
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.
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