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

Occasional crashes on app startup #5071

Closed
haikov opened this issue Nov 3, 2022 · 9 comments
Closed

Occasional crashes on app startup #5071

haikov opened this issue Nov 3, 2022 · 9 comments

Comments

@haikov
Copy link

haikov commented Nov 3, 2022

How frequently does the bug occur?

Sometimes

Description

Previously, with expo sdk 46 and realm 11.* app crashed on every app open in release build (which made sense, since realm 11 expects React Native 0.70). After upgrading expo SDK to latest beta, the app crashes on start in around 30% of cases in release mode with weird exception, I will attach the stack trace below.

I didn't have any luck reproducing it in nightly build or in the local release build with expo dev-client. The only reproducible case for now is building production app via EAS.

Environment:

"expo": "~47.0.0-beta.8",
"react-native": "0.70.4",
"realm": "11.1.0",
"@realm/react": "0.4.0",

What I can see in the logs (second line is caused by the first, I assume):

Unhandled JS Exception: Error: Missing Realm constructor. Did you run "pod install"? Please see https://docs.mongodb.com/realm/sdk/react-native/install/ for troubleshooting, js engine: hermes

Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
        A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

For additional context (I've seen those as reasons for crashes in other tickets):

  • I'm not using firebase libraries in my app.
  • Don't have useFrameworks set.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, sometimes

Reproduction Steps

No response

Version

11.1.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS

Build environment

No response

Cocoapods version

No response

@kneth
Copy link
Contributor

kneth commented Nov 3, 2022

@haikov Thank you for reporting. To be honest, we haven't tested the Expo 47 betas yet but it is on our radar. Did you enable Hermes or new architecture?

If it is possible for you to reproduce it, we will be interested to learn more. Any logs or stack traces can be useful too.

@haikov
Copy link
Author

haikov commented Nov 3, 2022

Did you enable Hermes or new architecture?

Yes, I have hermes enabled, but not the new architecture.

If it is possible for you to reproduce it, we will be interested to learn more. Any logs or stack traces can be useful too.

Trying to get some better logs or repro, but the fact that it only reproduces in EAS release builds makes it rather hard. I'll update here as soon as I have some additional information.

@kneth
Copy link
Contributor

kneth commented Nov 4, 2022

Thank you for trying to get more logs. We will also investigate it to understand the root cause.

@kneth
Copy link
Contributor

kneth commented Nov 4, 2022

@haikov Do you have dependencies like crashlytics installed?

@haikov
Copy link
Author

haikov commented Nov 4, 2022

Do you have dependencies like crashlytics installed?

No crashlytics in my case, from crash-reporting tools I have Sentry installed.

@jureczkyb
Copy link

I have encountered very similar issue after upgrading an app to the most recent RN and Realm versions.

Crash only happened in release mode and never in debug mode. More interesting when release mode started from xcode it never crashed. Also after installing or after phone restart it worked usually at least once. After killing the app it happens on subsequent starts randomly but not always.

In my case use_frameworks due to firebase also in the project and not using expo. Tried both Realm 10.23.0 and 11.1.0 and RN 0.70.3 and 0.70.4 with or without Hermes.

Symbolicating the traces from the firebase logs the crash always happens on this line in the code.
import Realm from 'realm';
Which calls (realm/lib/index.js):
const context = utils.getContext();
and then (realm/lib/utils.js:86)

            // Otherwise, we must be in a "normal" react native situation.
            // In that case, the Realm type should have been injected by the native code.
            // If it hasn't, the user likely forgot to install the RealmJS CocoaPod
            if (typeof Realm === "undefined") {
                throw new Error("Missing Realm constructor. Did you run \"pod install\"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting");
            }

It seems most cases (90% for me) Realm was not initialized by native code in time.

I found the following workaround: instead of importing Realm like above I used inline require in realm initialization:

	const Realm = require('realm');
	const db = new Realm(databaseOptions);

@MusabBasheer
Copy link

any update on this ??

@ammarlakho
Copy link

Facing the same issue in RN 0.70.6, realm 11.3.0. Any update?

@kneth
Copy link
Contributor

kneth commented Jul 13, 2023

I suggest to upgrade to v12.0.0-rc.1. If the problem is still observed, please create a new issue.

@kneth kneth closed this as completed Jul 13, 2023
@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

6 participants