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

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

  1. Login to account which causes realm database to be initialized
  2. 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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 18 (6 by maintainers)

Most upvoted comments

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

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

@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)

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

@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).

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