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 (or axios) causes hard crash on some URLs (but not others) #29196

Closed
hardcodet opened this issue Jun 23, 2020 · 10 comments
Closed

Fetch (or axios) causes hard crash on some URLs (but not others) #29196

hardcodet opened this issue Jun 23, 2020 · 10 comments
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@hardcodet
Copy link

Description

My app is crashing hard when doing API calls, and I narrowed it down to this point:

  • it's not an HTTP vs HTTPS thing
  • I eventually used two different mock APIs and one worked, the other didn't, both HTTP (see snippet below)
  • running on an Android device (no emulator): Galaxy S10e, Android 10
  • same behavior on both WIFI or cellular network
  • same issue in axios instead of fetch
  • the catch block is invoked, but then the app still crashes hard
async foo() {
        try {

            // this endpoint CRASHES my app
            const r = await fetch("http://jsonplaceholder.typicode.com/todos/1");
            
            // this endpoint works just fine
            //const r = await fetch("http://echo.jsontest.com/key/value/one/two");

        } catch(e) {
            console.log("Invoked with a non-descript network error, but the app still crashes hard right after");
        }
}

React Native version:

System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz
    Memory: 2.12 GB / 15.99 GB
  Binaries:
    Node: 12.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      API Levels: 23, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.2, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.2, 29.0.3
      System Images: android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6514223
  npmPackages:
    react: ~16.9.0 => 16.9.0
    react-native: ~0.61.5 => 0.61.5
  npmGlobalPackages:
    react-native-create-library: 3.1.2
    react-native-git-upgrade: 0.2.7

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Just invoke the snippet and replace one URL with the other.
  2. One crashes my app, the other one doesn't
@react-native-bot react-native-bot added Platform: iOS iOS applications. 🌐Networking Related to a networking API. labels Jun 23, 2020
@hardcodet
Copy link
Author

hardcodet commented Jun 23, 2020

I found a hint in Logcat - it appears that using OkHttp3 is causing some sort of versioning conflict that only manifests in one of the responses (maybe due to CORS headers, but that's completely unfounded speculation).

My fix was to change my dependency on OkHttp3 in build.gradle from

implementation "com.squareup.okhttp3:okhttp:4.7.2"

to

api(platform("com.squareup.okhttp3:okhttp-bom:4.7.2"))
api("com.squareup.okhttp3:okhttp")
api("com.squareup.okhttp3:logging-interceptor")

Can't say whether this is a proper fix, or a workaround to an underlying RN problem, so I'll keep this open for now for others to review. Thanks!

@latobibor
Copy link

We also have faced this issue and the workaround above fixes it. Please if there is official fix or workaround on this, let us know, so we can update the code (or bump the package).

@subhadeepshome1
Copy link

thanks @hardcodet in my case the issue is solved

@peterchibunna
Copy link

Thanks @hardcodet. This issue bugged me for days.

@Flip437
Copy link

Flip437 commented Feb 8, 2022

Hello everyone,

in my case, I didn't have this line in my ./android/build.gradle:

implementation "com.squareup.okhttp3:okhttp:4.7.2"

I tried to add it, but no luck, same error.

So I added those three lines in build.gradle:
api(platform("com.squareup.okhttp3:okhttp-bom:4.7.2")) api("com.squareup.okhttp3:okhttp") api("com.squareup.okhttp3:logging-interceptor")

and IT WORKED !!!

OMG, 2 days searching, this droves me crazy.

Thanks a lot guys.
Is there a fix planned for this issue ?

flip

@FrancescoBonizzi
Copy link

I face the same issue also on iOS, it's terrible.

Why try catch is not catching? 😭

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 15, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@vietnt-uet
Copy link

@FrancescoBonizzi Did you solve it, I face the kind of the same issue with my RN version 0.73.x in my iOS too. It's so weird.

@FrancescoBonizzi
Copy link

FrancescoBonizzi commented May 27, 2024

@FrancescoBonizzi Did you solve it, I face the kind of the same issue with my RN version 0.73.x in my iOS too. It's so weird.

Hi! I never solved it, unfortunately. I uninstalled Axios and went with fetch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

8 participants