Realm-js: Enabling React Native Debug mode causes Error: Must first create RPC session with a valid host from rpc.js:314

Created on 21 Oct 2020  路  18Comments  路  Source: realm/realm-js

Goals

Enable React Native Debug mode in order to troubleshoot console errors, set breakpoints, profile app, and monitor network requests.

Expected Results

Mobile app connects to React Native Debugger successfully and I'm able to set breakpoints, profile app, and monitor network requests, view console errors

Actual Results

  • Mobile App crashes with the following error

Error: Must first create RPC session with a valid host from rpc.js:314

:19

Mobile App

https://user-images.githubusercontent.com/222459/96701643-bea69400-1388-11eb-911e-9ee8323b2795.png

Sentry Stacktrace

Error: Must first create RPC session with a valid host
  File "app:///rpc.js", col 18, in sendRequest
  File "app:///rpc.js", col 41, in setTimeout$argument_0
  File "app:///JSTimers.js", col 17, in _allocateCallback$argument_0
  File "app:///JSTimers.js", col 6, in _callTimer
  File "app:///JSTimers.js", col 6, in callTimers
  at <unknown>(app:///RNDebuggerWorker.js:2:134503)

React Native Debugger console

https://user-images.githubusercontent.com/222459/96701668-c2d2b180-1388-11eb-9199-6c48c90085f9.png

Steps to Reproduce

  1. Run yarn android to build react native application and install on device
  2. Shake device to reveal developer menu and select Debug . This is successful if the user is not logged in

    image

  3. Login to account which causes realm database to be initialized

  4. An exception occurs on mobile app
![https://user-images.githubusercontent.com/222459/96701643-bea69400-1388-11eb-911e-9ee8323b2795.png](https://user-images.githubusercontent.com/222459/96701643-bea69400-1388-11eb-911e-9ee8323b2795.png)
The crash occurs when the following is called **`Realm.schemaVersion(Realm.defaultPath)`**     **`Realm.defaultPath`** displays an error when inspected using React Native debugger. See video below```

image

## Code Sample
<!---
Please provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists/repositories are preferred.
Full projects that we can compile and run ourselves are ideal!
-->

```jsx
export const runMigration = ({currentSchema}: {currentSchema: any}) => {
  if (!schemas.length) {
    return {schemaVersion: 0};
  }

  **let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath);**
  schemas[schemas.length - 1].schema = currentSchema;

  // If -1, it means this is a new Realm file, so no migration is needed
  if (nextSchemaIndex !== -1) {
    while (nextSchemaIndex < schemas.length) {
      const migratedRealm = new Realm(schemas[nextSchemaIndex++]);
      migratedRealm.close();
    }
  }

  return {schemaVersion: schemas[schemas.length - 1].schemaVersion};
};

Version of Realm and Tooling

  • Realm JS SDK Version: 10.0.1
  • Node or React Native: 0.63.3
  • Client OS & Version: OnePlus 6 A6003, Android 10
  • Which debugger for React Native: React Native Debugger
O-Community

Most helpful comment

Thank for reporting. It is a bug that we need to fix.

All 18 comments

I have the exact same issue. realm 10.0.1 and react-native": "0.63.3
Sample code:

Screenshot 2020-10-23 at 12 55 58 PM

Same thing happening here on iOS. It happens when I call Realm.open(myConfig) while running Remote Debug.

Same with RN 63.2 and Realm 10.0.1.

Thank for reporting. It is a bug that we need to fix.

@kneth kindly fix this bug ASAP.

Without seeing logging from chrome. Its been very difficult and time consuming to verify db data on shell.

@Muzzamil75 We are working on it but I can't say when we have a fix.

@kneth Kindly make merge with the master after all your fixes !

This is blocking us from using realm for a project we want to beta asap - mainly for offline. We do appreciate your effort in resolving the issue. Realm looks like a perfect fit for us once this issue is fixed.

After fixing the RPC session bug, we ran into a couple of other issues which we are still working on.

If you can debug on iOS for now, I suggest that you use Safari's debugger tools. You can follow the guide at https://reactnative.dev/docs/debugging#safari-developer-tools and in particular the change to AppDelegate.m as outlined in http://blog.nparashuram.com/2019/10/debugging-react-native-ios-apps-with.html.

After fixing the RPC session bug, we ran into a couple of other issues which we are still working on.

If you can debug on iOS for now, I suggest that you use Safari's debugger tools. You can follow the guide at https://reactnative.dev/docs/debugging#safari-developer-tools and in particular the change to AppDelegate.m as outlined in http://blog.nparashuram.com/2019/10/debugging-react-native-ios-apps-with.html.

Know you are working on some solution is amazing, thank you for your reply, I really appreciate your efforts to fix this.

Started using Realm for a new project this week. Really looking forward for a fix for this one.

I have been working on a PR (continuing @kneth's work) here: https://github.com/realm/realm-js/pull/3411.
I am currently incorporating comments from code review, but if you're currently blocked on this it might be interesting to clone the branch and start using it already (but expect this branch to disappear once it's merged):

npm install https://github.com/realm/realm-js.git#kh/rn-create-session-continued

@kraenhansen thanks for this.

I just tried to install realm from the given branch and pod install after that. I'm getting the error: 'property.hpp' file not found.

@kraenhansen Thanks for getting a PR out for this so quickly. However, I tried 10.0.2, the version this was fixed in, and I'm still getting this error. The stack trace in the React Native debugger appear to be the same as OP. Let me know if I can provide any more information to help debug this.

Realm: 10.0.2
React Native: 0.63.3
Android Stack Trace:

2020-12-06 15:32:00.778 30006-30673/com.interviewbuddy E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by Networking
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:67)
        at com.facebook.react.modules.network.NetworkingModule.getEventEmitter(NetworkingModule.java:767)
        at com.facebook.react.modules.network.NetworkingModule.sendRequestInternal(NetworkingModule.java:273)
        at com.facebook.react.modules.network.NetworkingModule.sendRequest(NetworkingModule.java:243)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:923)
2020-12-06 15:32:00.780 30006-30006/com.interviewbuddy E/unknown:ReactInstanceManager: destroyRootView called
2020-12-06 15:32:00.780 30006-30006/com.interviewbuddy E/unknown:ReactInstanceManager: destroyRootView called, unmountReactApplication
2020-12-06 15:32:00.797 30006-30812/com.interviewbuddy E/unknown:ReactNative: ReactInstanceManager.createReactContext: mJSIModulePackage null
2020-12-06 15:32:00.798 30006-30817/com.interviewbuddy E/unknown:ReactNative: ReactInstanceManager.attachRootViewToInstance()
2020-12-06 15:32:00.856 30006-30817/com.interviewbuddy E/unknown:ReactRootView: runApplication: call AppRegistry.runApplication
2020-12-06 15:32:01.010 30006-30006/com.interviewbuddy E/unknown:ReactNative: ReactInstanceManager.attachRootViewToInstance()
2020-12-06 15:32:01.011 30006-30006/com.interviewbuddy E/unknown:ReactRootView: runApplication: call AppRegistry.runApplication
2020-12-06 15:32:02.465 30006-30082/com.interviewbuddy E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by WebSocketModule
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:67)
        at com.facebook.react.modules.websocket.WebSocketModule.sendEvent(WebSocketModule.java:62)
        at com.facebook.react.modules.websocket.WebSocketModule.access$100(WebSocketModule.java:40)
        at com.facebook.react.modules.websocket.WebSocketModule$1.onMessage(WebSocketModule.java:190)
        at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.java:323)
        at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:219)
        at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:105)
        at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:274)
        at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:214)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

I am still getting this error even with realm 10.1.0. Anyone else?
Setup
react-native: 63.3
realm: 10.1.0
react native debugger 11.5 (https://github.com/jhen0409)

image

GET /debugger-ui/debuggerWorker.aca173c4.js HTTP/1.1" 404

@Muzzamil75 This 404 is an error when the Chrome browser fails to fetch the React Native debugger UI and as such is unrelated to Realm JS.

@Ninjaman494 & @jbstinson for transparency: I'm currently working on a fix for an issue related to the chrome debugger which shows itself when running an app that uses the BSON ObjectId or Decimal128 types (see #3452 and #3454 and my PR #3456 for context).

@kraenhansen Thanks for the heads up! I'm using synced realms so I suspect my issue is caused by this

Was this page helpful?
0 / 5 - 0 ratings