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

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

Closed
shawlz opened this issue Oct 21, 2020 · 18 comments · Fixed by #3411
Assignees

Comments

@shawlz
Copy link

shawlz commented Oct 21, 2020

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
@shawlz shawlz changed the title When enabling React Native Debug mode I get Error: Must first create RPC session with a valid host from rpc.js React Native Debug mode causes Error: Must first create RPC session with a valid host from rpc.js:314 Oct 21, 2020
@shawlz shawlz changed the title React Native Debug mode causes Error: Must first create RPC session with a valid host from rpc.js:314 Enabling React Native Debug mode causes Error: Must first create RPC session with a valid host from rpc.js:314 Oct 21, 2020
@jeffpc1993
Copy link

jeffpc1993 commented Oct 23, 2020

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

@MrGVSV
Copy link

MrGVSV commented Oct 24, 2020

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

@wgarrido
Copy link

Same with RN 63.2 and Realm 10.0.1.

@kneth
Copy link
Contributor

kneth commented Oct 26, 2020

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

@Muzzamil75
Copy link

@kneth kindly fix this bug ASAP.

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

@kneth
Copy link
Contributor

kneth commented Oct 28, 2020

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

@kneth kneth mentioned this issue Oct 29, 2020
8 tasks
@Muzzamil75
Copy link

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

@tonygomez
Copy link

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.

@kneth
Copy link
Contributor

kneth commented Nov 4, 2020

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.

@mendesbarreto
Copy link

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.

@uripre
Copy link

uripre commented Nov 11, 2020

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

@kraenhansen
Copy link
Member

I have been working on a PR (continuing @kneth's work) here: #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

@ennesp
Copy link

ennesp commented Nov 25, 2020

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

@realm realm deleted a comment from sync-by-unito bot Nov 30, 2020
@Ninjaman494
Copy link

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

@jbstinson
Copy link

jbstinson commented Dec 9, 2020

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

@kraenhansen
Copy link
Member

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.

@kraenhansen
Copy link
Member

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

@Ninjaman494
Copy link

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

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

Successfully merging a pull request may close this issue.