react-native: Remote JS Debugging crashes app after 30 seconds

Description

When using Remote JS Debugging the app crashes after exactly 30 seconds.

Without Remote JS Debugging the app works just fine.

Reproduction

This also happens on a brand new project created like this:

react-native init AwesomeProject
cd AwesomeProject
react-native run-android

Just enable Remote JS Debugging, reload and wait for 30 seconds - the app will crash.

Solution

?

Additional Information

  • React Native version: 0.41.2
  • Platform: Android (haven’t tried IOS yet)
  • Operating System: Windows (haven’t tried macOS yet)
  • JS Debugger: Chrome Dev Tools, React Native Debugger

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 41
  • Comments: 35 (5 by maintainers)

Most upvoted comments

The issue seems to be that the React Native code is running a network call on the UI Thread 🤦‍♂️ So I have a workaround…

NOTE: Don’t ship this in your release builds as you should never run network calls on the UI Thread. This workaround is just to get debugging working until a proper fix is made by Facebook

In MainApplication.java do the following…

  @Override
  public void onCreate() {
    // There is a bug in React Native preventing remote debugging on Android
    // https://github.com/facebook/react-native/issues/12289
    //
    // This is a hack to get around it. Make sure you remove it before releasing
    // as you should never run network calls on the main thread
    if (BuildConfig.DEBUG) {
      strictModePermitAll();
    }

    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }

  private static void strictModePermitAll() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    if (Build.VERSION.SDK_INT >= 16) {
      //restore strict mode after onCreate() returns. https://issuetracker.google.com/issues/36951662
      new Handler().postAtFrontOfQueue(new Runnable() {
        @Override
        public void run() {
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
        }
      });
    }
  }

I am still getting same error

“react-native”: “0.47.1”,

nw_connection_get_connected_socket 287 Connection has no connected handler TCP Conn 0x60000017ce00 Failed : error 0:61 [61]

Still happening to me with RN 0.51.0 and 0.52.0

Looking for help!!!

In order to get @mrbrentkelly workaround compiled, add these 3 lines on top:

import android.os.StrictMode; 
import android.os.Build; 
import android.os.Handler;

Unfortunately the app will still crash as soon as Remote Debugger Mode was activated.

Anything new about this issue? It’s really a pain to develop with the debugger on, as the app crashes 50% of the time when reloading 😞

React Native version: 0.38.0 IOS

It crashes my app right after I open it

I’m having this problem on 0.60.0

"dependencies": {
    "react": "16.8.6",
    "react-native": "^0.60.0",
  }
implementation "com.facebook.react:react-native:0.60.0"
No implementation found for com.facebook.react.bridge.Inspector

UPDATE: I was updating my project when finding the error, so to make sure I create a new one from scratch. The problem is not solved, the error is the same.

This line in AndroidManifest.xml may help:

    <uses-permission android:name="android.permission.TYPE_APPLICATION_OVERLAY"/>

Read more:

Crashes right after turning debug on from the dev menu

React Native version: 0.42 Platform: iOS OS: OS X 10.11.6 JS Debugger: Chrome Dev Tools, React Native Debugger