[iOS] Extra instances of RCTBridge don't get instantiated when Realm is used
backmeupplz opened this issue · 7 comments
Goals
I'm trying to create an extra RCTBridge instance in React Native to offload CPU-intensive tasks to a separate React Native instance. It works well, see this example I made.
Then I do yarn add realm && npx pod-install
, which adds Realm to the project, and rebuild the app.
Expected Results
Both the main React Native bridge and my separate new RCTBridge for the sync process are instantiated and work well.
Actual Results
All of a sudden only the first RCTBridge instance gets instantiated. The second one either never gets created or halts in a deadlock?
Steps to Reproduce
- Clone https://github.com/backmeupplz/react-native-ios-threading-example
- Install dependencies —
yarn && npx pod-install
- Launch Reactotron
- Launch the app, observe both the React Native main thread and the separate Sync thread to start logging to Reactotron
- Install Realm —
yarn add realm && npx pod-install
- Launch the app, observe only the React Native main thread to log to Reactotron, and Sync thread not being launched at all
- You can then switch the order or RCTBridge instantiations in the
AppDelegate.m
to verify that only the first instance of RCTBridge gets instantiated
Code Sample
https://github.com/backmeupplz/react-native-ios-threading-example
Version of Realm and Tooling
- Realm JS SDK Version: tested the issue on
6.1.5
and10.1.3
, both have this issue - Node or React Native: tested the issue on
0.63.3
and0.63.4
, both have the issue - Client OS & Version: iOS 14.2, simulator, React Native dev mode
- Which debugger for React Native: I use Reactotron to keep track of multiple RCTBridge instances' logs
Extra info
In my particular case, I use React Native as the app that the user uses and a separate RCTBridge handles the synchronization logic between local Realm storage and my backend. But the example here is simplified to just show you the reproducible issue.
From what it seems like, Realm also creates its own RCTBridge instances and modifies the built-in RCTBridge logic?
Looks like this is an iOS-only issue, hence I only tested the above example on iOS.
Hm, it seems like Realm uses RCTBridge as any other native module 🤔 however, when I use other native modules, the extra RCTBridge instance still works well, it's only when I add Realm the things break.
When adding Realm dependency, GCDWebServer
pod also gets added. I installed this pod separately without Realm and RCTBridge still worked well when Realm wasn't installed. When I added Realm, the GCDWebServer
dependency wasn't updated (so the versions probably match) and RCTBridge began strange behaviour again.
Hm, [RealmReact setBridge:]
is called twice: once per RCTBridge that I create. The parent bridges are correspondent to the bridges I create.
Oh, I see now. Realm doesn't support multithreading yet: #2117. Well, it was worth trying.
Thank you for the comprehensive bug report. Although Realm JS might have an issue supporting this use-case, I would still expect that the library wouldn't interfere with the creation of multiple RCTBridge
instances. And in any case, I doubt that this behaviour is well documented. I will therefore leave this issue open and add it to our backlog as a piece of technical debt that we need to investigate further.
Closing this as it will be resolved with the support for Hermes and the Flipper debugger. Please see here to try it out and provide feedback. Thanks for your patience!
@backmeupplz Was the issue resolved with @bmunkholm 's solution?
Thanks!