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

[iOS] Extra instances of RCTBridge don't get instantiated when Realm is used #3522

Closed
backmeupplz opened this issue Jan 25, 2021 · 7 comments
Assignees

Comments

@backmeupplz
Copy link

backmeupplz commented Jan 25, 2021

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

  1. Clone https://github.com/backmeupplz/react-native-ios-threading-example
  2. Install dependencies — yarn && npx pod-install
  3. Launch Reactotron
  4. Launch the app, observe both the React Native main thread and the separate Sync thread to start logging to Reactotron
  5. Install Realm — yarn add realm && npx pod-install
  6. Launch the app, observe only the React Native main thread to log to Reactotron, and Sync thread not being launched at all
  7. 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 and 10.1.3, both have this issue
  • Node or React Native: tested the issue on 0.63.3 and 0.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.

@backmeupplz backmeupplz changed the title How can I create new instances of RCTBridge when Realm is used? [iOS] How can I create new instances of RCTBridge when Realm is used? Jan 25, 2021
@backmeupplz backmeupplz changed the title [iOS] How can I create new instances of RCTBridge when Realm is used? [iOS] Extra instances of RCTBridge don't get instantiated when Realm is used Jan 25, 2021
@backmeupplz
Copy link
Author

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.

@backmeupplz
Copy link
Author

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.

@backmeupplz
Copy link
Author

Hm, [RealmReact setBridge:] is called twice: once per RCTBridge that I create. The parent bridges are correspondent to the bridges I create.

@backmeupplz
Copy link
Author

Oh, I see now. Realm doesn't support multithreading yet: #2117. Well, it was worth trying.

@kraenhansen
Copy link
Member

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.

@sync-by-unito sync-by-unito bot removed the T-Bug label Jan 26, 2021
@bmunkholm
Copy link
Contributor

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!

@hayr-hotoca
Copy link

@backmeupplz Was the issue resolved with @bmunkholm 's solution?
Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants