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

Created on 8 Feb 2017  ·  35Comments  ·  Source: facebook/react-native

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
Bug DX Follow Up JavaScript Locked

Most helpful comment

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);
        }
      });
    }
  }

All 35 comments

i also faced this problem

Additional Information

  • React Native version: 0.41.2
  • Platform: Android
  • Operating System: Kali Linux(Debian)
  • JS Debugger: Chrome Dev Tools, React Native Debugger

React Native version: 0.38.0
IOS

It crashes my app right after I open it

React Native version: 0.41.2
Platform: Android device 7.1.2
OS: macOS
JS Debugger: Chrome Dev Tools, React Native Debugger

Android error: FATAL EXCEPTION: main
                                                               Process: com.myapp, PID: 30655
                                                               android.os.NetworkOnMainThreadException
                                                                   at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
                                                                   at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
                                                                   at java.net.SocketOutputStream.write(SocketOutputStream.java:157)
                                                                   at okio.Okio$1.write(Okio.java:78)
                                                                   at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
                                                                   at okio.RealBufferedSink.emit(RealBufferedSink.java:178)
                                                                   at okhttp3.internal.ws.WebSocketWriter.writeControlFrameSynchronized(WebSocketWriter.java:152)
                                                                   at okhttp3.internal.ws.WebSocketWriter.writeClose(WebSocketWriter.java:111)
                                                                   at okhttp3.internal.ws.RealWebSocket.close(RealWebSocket.java:168)
                                                                   at com.facebook.react.devsupport.JSDebuggerWebSocketClient.closeQuietly(JSDebuggerWebSocketClient.java:144)
                                                                   at com.facebook.react.devsupport.WebsocketJavaScriptExecutor$3.run(WebsocketJavaScriptExecutor.java:146)
                                                                   at android.os.Handler.handleCallback(Handler.java:751)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                   at android.os.Looper.loop(Looper.java:154)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

Same happens here
React Native version: 0.41.2
Platform: Android device 7.1.1
OS: macOS
JS Debugger: Chrome Dev Tools, React Native Debugger

FATAL EXCEPTION: main
                                                            Process: com.albums, PID: 11375
                                                            android.os.NetworkOnMainThreadException
                                                                at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
                                                                at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
                                                                at java.net.SocketOutputStream.write(SocketOutputStream.java:157)
                                                                at okio.Okio$1.write(Okio.java:78)
                                                                at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
                                                                at okio.RealBufferedSink.emit(RealBufferedSink.java:178)
                                                                at okhttp3.internal.ws.WebSocketWriter.writeControlFrameSynchronized(WebSocketWriter.java:152)
                                                                at okhttp3.internal.ws.WebSocketWriter.writeClose(WebSocketWriter.java:111)
                                                                at okhttp3.internal.ws.RealWebSocket.close(RealWebSocket.java:168)
                                                                at com.facebook.react.devsupport.JSDebuggerWebSocketClient.closeQuietly(JSDebuggerWebSocketClient.java:144)
                                                                at com.facebook.react.devsupport.WebsocketJavaScriptExecutor$3.run(WebsocketJavaScriptExecutor.java:146)
                                                                at android.os.Handler.handleCallback(Handler.java:751)
                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                at android.os.Looper.loop(Looper.java:154)
                                                                at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

I have the same problem

React Native version: 0.42
Platform: Android device 7.1.1
OS: macOS 10.12.3
JS Debugger: Chrome Dev Tools, React Native Debugger

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

Crashes after ~30 seconds, if it is paused in debugger everything is fine

03-22 11:09:23.844 25887-25887/com.halebop.servicetips.dev E/art: No implementation found for com.facebook.react.bridge.Inspector com.facebook.react.bridge.Inspector.instance() (tried Java_com_facebook_react_bridge_Inspector_instance and Java_com_facebook_react_bridge_Inspector_instance__)
03-22 11:10:48.718 25887-2669/? E/UncaughtException: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
                                                         at java.lang.Thread.nativeCreate(Native Method)
                                                         at java.lang.Thread.start(Thread.java:1063)
                                                         at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921)
                                                         at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)
                                                         at okhttp3.ConnectionPool.put(ConnectionPool.java:135)
                                                         at okhttp3.OkHttpClient$1.put(OkHttpClient.java:149)
                                                         at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:188)
                                                         at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
                                                         at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
                                                         at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                                         at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                                         at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                         at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                         at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                                         at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
                                                         at okhttp3.RealCall.access$100(RealCall.java:33)
                                                         at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
                                                         at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                         at java.lang.Thread.run(Thread.java:818)

React Native version: 0.42
Platform: Android 6
OS: OS X 10.12.3
JS Debugger: Chrome Dev Tools, React Native Debugger

Same issue here. App crashes a few seconds after enabling remote debugging on my Android Emulator

RN: 0.42.3
Android 7.1.1
OS X 10.12.3

03-31 22:25:33.362 3244-3244/com.vscodetest E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: com.vscodetest, PID: 3244
                                                              android.os.NetworkOnMainThreadException
                                                                  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
                                                                  at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
                                                                  at java.net.SocketOutputStream.write(SocketOutputStream.java:157)
                                                                  at okio.Okio$1.write(Okio.java:78)
                                                                  at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
                                                                  at okio.RealBufferedSink.emit(RealBufferedSink.java:178)
                                                                  at okhttp3.internal.ws.WebSocketWriter.writeControlFrameSynchronized(WebSocketWriter.java:152)
                                                                  at okhttp3.internal.ws.WebSocketWriter.writeClose(WebSocketWriter.java:111)
                                                                  at okhttp3.internal.ws.RealWebSocket.close(RealWebSocket.java:168)
                                                                  at com.facebook.react.devsupport.JSDebuggerWebSocketClient.closeQuietly(JSDebuggerWebSocketClient.java:144)
                                                                  at com.facebook.react.devsupport.WebsocketJavaScriptExecutor$3.run(WebsocketJavaScriptExecutor.java:146)
                                                                  at android.os.Handler.handleCallback(Handler.java:751)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Like a four car pileup

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

Getting the same error in my environment.

react-native: 0.43.3
Platform: Android
OS: macOS 10.12.4
JS Debugger: Chrome Dev Tools

Same issue here debugging android

React-native: 0.40.0
Platform: Android
OS: macOS 10.12.4
JS Debugger: Chrome Dev Tools, React Native Debugger

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);
        }
      });
    }
  }

@mrbrentkelly thank you very much for the fix! It's been over a week month and this is a high priority issue for Android users - would be great to see an official fix soon!

@mrbrentkelly This has not solved the issue yet

Same issue here debugging android

React-native: 0.45.1
Platform: Android
OS: WIN7
JS Debugger: Chrome Dev Tools, React Native Debugger

@mrbrentkelly thank you for this fix, but it doesn't work for me.

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.

Facing same issue: @mrbrentkelly

"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
Platform: Android
OS: WIN7
JS Debugger: Chrome Dev Tools, React Native Debugger

same issue here

react-native-cli: 2.0.1
react-native: 0.44.0

android-26 x86 (Android 8.0.0)
App crashes after typing [CMD] + [M] (open debug window)

Unable to add window android.view.ViewRootImpl$W@bd91ba -- permission denied for window type 2003

Permissions are enabled:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" tools:node="remove"/>

Code from @mrbrentkelly added, thanks, but no lack.

Update:
I have to remove all tools:node="remove" in xml

This line in AndroidManifest.xml may help:

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

Read more:

@iegik android.permission.TYPE_APPLICATION_OVERLAY doesn't exist. You should use the same SYSTEM_ALERT_WINDOW permission to request TYPE_APPLICATION_OVERLAY

See https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_APPLICATION_OVERLAY

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 😞

I've also run into very frequent crashes when working with the remote debugger on android.

"react": "16.0.0",
"react-native": "0.50.1",
Platform: Android
OS: OSX
JS Debugger: Chrome Dev Tools

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

Still happening to me with RN 0.51.0 and 0.52.0

Looking for help!!!!

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]

"react-native": "0.44.3",
platform : ios
TCP Conn 0x60400356bf40 Failed : error 0:61 [61]
nw_connection_get_connected_socket 280 Connection has no connected handler

Still an issue with:

"react": "16.3.1",
"react-native": "0.55.4",
Platform: Android
OS: Win10
JS Debugger: Chrome Dev Tools

I solved the issue by disabling 'remote-redux-devtools': in my createStore call i have deleted the composeWithDevTools call. So, sobstitute

const store = createStore (
    persistedReducer,
    composeWithDevTools(applyMiddleware(thunk))
)

with

const store = createStore (
    persistedReducer,
    applyMiddleware(thunk)
)

when is this issue going to be resolved. FACEBOOK!!!

Can anyone reproduce this issue on a freshly init'd project with 59-rc3?

Hello there 👋 this issue seems to have been inactive for the past few weeks. Because of this, it's likely that the issue is not a high priority anymore or it has been solved by OP; for these reasons, we'll close it. But please, if it's actually still an issue with 0.59 please comment below and we can reopen it or please send us a Pull Request with a fix 😊

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.

The same problem in react native 0.60.0

Here's the complete log in my case:

07-05 00:06:26.708 15134 15170 E unknown:ReactNative: java.lang.UnsatisfiedLinkError: No implementation found for com.facebook.react.bridge.Inspector com.facebook.react.bridge.Inspector.instance() (tried Java_com_facebook_react_bridge_Inspector_instance and Java_com_facebook_react_bridge_Inspector_instance__)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at com.facebook.react.bridge.Inspector.instance(Native Method)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at com.facebook.react.bridge.Inspector.getPages(Inspector.java:27)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at com.facebook.react.devsupport.InspectorPackagerConnection.getPages(InspectorPackagerConnection.java:152)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at com.facebook.react.devsupport.InspectorPackagerConnection.handleProxyMessage(InspectorPackagerConnection.java:72)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at com.facebook.react.devsupport.InspectorPackagerConnection$Connection.onMessage(InspectorPackagerConnection.java:223)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.java:323)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:219)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:105)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:274)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:214)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
07-05 00:06:26.708 15134 15170 E unknown:ReactNative:   at java.lang.Thread.run(Thread.java:764)

@mehulmpt as far as I know java.lang.UnsatisfiedLinkError means there is a dependency missing. Somehow the code got packaged, and then when the file, class, method is needed, is not there, Java crashes.

Hey is there any solution to this ?? I am still unable to debug the app.

Was this page helpful?
0 / 5 - 0 ratings