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

Fetch operations not working inside nativehandler #168

Open
W1nstar opened this issue Aug 3, 2022 · 2 comments
Open

Fetch operations not working inside nativehandler #168

W1nstar opened this issue Aug 3, 2022 · 2 comments

Comments

@W1nstar
Copy link

W1nstar commented Aug 3, 2022

I get the native UI when the rn-test-exception-handler is called, and the JS code executes till the fetch, where it stops without error of any kind.

const nativeErrorHandler = async (error, isFatal) => {
  // Log error to Sentry
  console.log("1 coming from JAVA")
  try {
    console.log("2 going for a fetch fetch")
    await fetch('https://jsonplaceholder.typicode.com/users')
    console.log("3 fetch done")
  } catch (e) {
    console.log("4 something failed", e)
  }
  

};

setNativeExceptionHandler(nativeErrorHandler, false);

And this is how the logcat reads:

    --------- beginning of crash
2022-08-03 12:21:15.436 7832-7863/com.mobilea E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.mobilea, PID: 7832
    java.lang.RuntimeException: Could not invoke RnTestExceptionHandler.raiseTestNativeError
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:382)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
        at android.os.Looper.loop(Looper.java:193)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150) 
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26) 
        at android.os.Looper.loop(Looper.java:193) 
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.Exception: TEST EXCEPTION ON ANDROID
        at com.masteratul.rn.testexception.RnTestExceptionHandlerModule.raiseTestNativeError(RnTestExceptionHandlerModule.java:27)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371) 
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150) 
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26) 
        at android.os.Looper.loop(Looper.java:193) 
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225) 
        at java.lang.Thread.run(Thread.java:764) 
2022-08-03 12:21:15.406 7832-7862/com.mobilea I/chatty: uid=10091(com.mobilea) mqt_js identical 2 lines
2022-08-03 12:21:15.406 7832-7862/com.mobilea I/ReactNativeJS: 'child.type.name', [Function: b]
2022-08-03 12:21:15.436 7832-7863/com.mobilea D/debug en java prueba 2: prueba
2022-08-03 12:21:15.437 7832-7863/com.mobilea D/debug en java prueba 4: prueba
    
    --------- beginning of system
2022-08-03 12:21:15.450 7832-7862/com.mobilea I/ReactNativeJS: 1 coming from JAVA
2022-08-03 12:21:15.450 7832-7862/com.mobilea I/ReactNativeJS: 2 going for a fetch fetch
2022-08-03 12:21:15.450 7832-7832/com.mobilea W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@4497442
2022-08-03 12:21:15.524 7832-7860/com.mobilea D/EGL_emulation: eglMakeCurrent: 0xe5e6b320: ver 2 0 (tinfo 0xd56cc2e0)
2022-08-03 12:21:16.138 7832-7832/com.mobilea D/ReactNative: ReactInstanceManager.detachViewFromInstance()

Android Studio's network inspector shows no internet usage at all.

Any idea of what's going on? Workaround? Tried axios, same thing happens. Tried referencing methods defined outside the handler function and they work. It looks like any http request will fail, but without error.

@W1nstar
Copy link
Author

W1nstar commented Aug 3, 2022

Did some more digging, tried an xhr instead of a fetch and it only chages state when I open it, it never gets sent. Changes state to status 0 readyState 1 on open, though.

A console.log of the fetch function shows { [Function: O] polyfill: true }, so it seems like it's there.

Still, I don't know what's happening. It's like the apk isn't capable of networking after crash or something, but since nothing errors I can't confirm it.

@W1nstar
Copy link
Author

W1nstar commented Aug 4, 2022

After some more digging, I found that if I do callbackHolder.invoke() right as it's stored, it does have access to internet and makes the fetch corrrectly, or any other operation like post or calling to your crash api.

It'd seem that there are no network capabilities once the app has crashed with a native exception, but I don't have enough knowledge to ensure that, and it goes against what we can see in the docs of this project.

Hope someone can throw some light here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant