Skip to content

Network requests silently fail in Android since v0.63.0 #29608

Closed

Description

@scobo

Description

None of the network examples work in Android since v0.63.0; iOS is unaffected. Confirmed this is still an issue in v0.63.1 and v0.63.2 (the latest as of this report). Failures are silent and simply result in no data being returned to the view.

Since this is an issue with the network APIs, this affects all libraries that rely on those APIs, e.g., Apollo.

React Native version:

System:
    OS: macOS 10.15.6
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 960.03 MB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.2 - /var/folders/tb/wx5d6rj53qjdg6sr4bmb1l840000gn/T/yarn--1597082804831-0.5290956210609348/node
    Yarn: 1.22.4 - /var/folders/tb/wx5d6rj53qjdg6sr4bmb1l840000gn/T/yarn--1597082804831-0.5290956210609348/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.8 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.2 => 0.63.2 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Install the last known good version:
  2. npx react-native init AwesomeProject --version 0.62.2
  3. Replace the contents of App.js with one of the examples from the network docs, e.g., the Fetch Example.
  4. Run the application in iOS.
  5. npx react-native run-ios
  6. Note that the fetch example displays as intended.
  7. Run the application in Android.
  8. npx react-native run-android
  9. Note that the fetch example displays as intended.
  10. Install latest (v0.63.2 as of this report):
  11. npx react-native init AwesomeProject
  12. Replace the contents of App.js with one of the examples from the network docs, e.g., the Fetch Example.
  13. Run the application in iOS.
  14. npx react-native run-ios
  15. Note that the fetch example displays as intended.
  16. Run the application in Android.
  17. npx react-native run-android
  18. Note that a blank screen is rendered.

Expected Results

The results should be rendered as they are on iOS and as they are on versions prior to v0.63.0. At the very least, would expect to see the activity indicator and possibly an error indicating the request failed.

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/2HgnLjyI_

Activity

  1. scobo commented on Aug 10, 2020

    @scobo
    Author
  2. scobo commented on Aug 10, 2020

    @scobo
    Author

    With further testing, it seems v0.62.x releases do not work with iOS. Had to downgrade to v0.61.5 to get a release where the network examples work for both platforms.

  3. safaiyeh commented on Aug 11, 2020

    @safaiyeh
    Contributor

    Hi @scobo thanks for the issue.

    I checked out the example and tested it out locally. I did not see the same issue you are experiencing.

    Could you provide a repo?

    Screen Shot 2020-08-10 at 7 29 43 PM

  4. scobo commented on Aug 12, 2020

    @scobo
    Author

    This was 100% repro for us and now it’s zero. I have no idea what was wrong.

  5. reopened this on Aug 12, 2020
  6. scobo commented on Aug 12, 2020

    @scobo
    Author

    Repro again. AFACIT all I did to trigger it was cd android/ && ./gradlew clean. After that, network requests in Android fail silently 100% of the time.

  7. scobo commented on Aug 12, 2020

    @scobo
    Author

    100% repro with the following steps.

    1. npx react-native foobar --version 0.63.2
    2. cd foobar
    3. npx react-native run-android
    4. View demo/welcome screen.
    5. Replace App.js contents with fetch example (see Snack link above).
    6. Refresh app with R in Metro console.
    7. Blank screen. Expected: List of movies with years.
    8. Uninstall app.
    9. Ctrl+C to shut down Metro and close window.
    10. cd .. && rm -rf foobar
    11. Repeat from step 1.
  8. scobo commented on Aug 12, 2020

    @scobo
    Author

    Same result on iOS now.

    Flipper indicates the request was successful and I can inspect the response there, but isLoading is true in the app and data is an empty array.

  9. 13 remaining items

  10. scobo commented on Aug 26, 2020

    @scobo
    Author

    No code changes since yesterday, yet today neither the demo app or the one in our monorepo have network connectivity. We’ve tried building from both macOS (two separate machines) and Ubuntu; same result in both environments. Flipper still indicates the requests are successful (and we can access the URL directly from a browser), but there’s nothing in render in the app.

  11. scobo commented on Aug 26, 2020

    @scobo
    Author

    Ran into a separate issue when trying to repro with an earlier version: #29781

  12. snowloop commented on Aug 27, 2020

    @snowloop

    Hi,

    I might have the same issue, did you mean that you can't do any http request or socket connection with any server from your android application ?
    Because that's exactly my situation, the android phone is connected but my RN android app can't connect with my server.

    Have a nice day

  13. scobo commented on Aug 28, 2020

    @scobo
    Author

    Today’s update: Was able to install an older version of the CLI and successfully run the fetch example from the docs in React Native v0.59.10. However, the same App.js fails to render when using React Native v0.63.2. This is in a separate directory created via react-native init, not our monorepo. The issue seems to be with React Native itself.

  14. scobo commented on Aug 31, 2020

    @scobo
    Author

    From macOS, with both a Pixel 2 emulator and a Pixel 4 device:

    1. npx react-native init AwesomeProject
    2. cd AwesomeProject
    3. npx react-native run-android
    4. Demo page renders.
    5. Copy & paste fetch example into App.js.
    6. Refresh app via R from Metro console
    7. Empty render.

    From Ubuntu 18.04, with both a Pixel 3 emulator and a Pixel 4 device:

    1. npx react-native init AwesomeProject
    2. cd AwesomeProject
    3. npx react-native run-android
    4. npx react-native start (run-android doesn’t seem to automatically launch Metro in Ubuntu.)
    5. Demo page renders.
    6. Copy & paste fetch example into App.js.
    7. Refresh app via R from Metro console
    8. Empty render.

    Flipper indicates the network request was successful. Closing Flipper and refreshing the app has no affect on the outcome.

  15. scobo commented on Aug 31, 2020

    @scobo
    Author

    @yungsters Can you try to repro by invoking react-native via Yarn?

    1. npx react-native init AwesomeProject
    2. cd AwesomeProject
    3. yarn react-native start
    4. yarn react-native run-android

    We repro’d on a “clean” machine which was able to run the fetch example successfully via npx. Subsequently invoking yarn react-native start seemed to “poison“ the machine and network requests would no longer work (on emulators or devices), even after switching back to npx react-native.

  16. scobo commented on Aug 31, 2020

    @scobo
    Author

    More info: If we invoke Metro via yarn in our monorepo, it seems to “poison” the Metro cache. Running yarn react-native --reset-cache in the monorepo has no effect. We have to create a demo app with the same package name to clean it, e.g., npx react-native init <ourproject> && cd <ourproject> && npx react-native start --reset-cache, then the app works again. It appears Metro caches based on the project name, is that accurate?

    Also, while this workaround works for the development builds, the release builds still have no network connectivity, e.g., npx react-native run-android works but not npx react-native run-android --variant=release.

    Edit: Running a release build also appears to “poison” the Metro cache.

  17. scobo commented on Sep 2, 2020

    @scobo
    Author

    Closing this issue since we’ve verified that un-poisoning the Metro cache by running a demo app with the same package name allows us to run debug and release builds of the demo app successfully.

    It’s still not clear, however, what the issue is when running in our monorepo or how or why running the app in our monorepo poisons the Metro cache for all React Native apps. Since Flipper indicates the network requests are successful, we’re at a loss on how to debug the issue. Any help would be appreciated.

  18. higoramp commented on Dec 6, 2020

    @higoramp

    I'm having a similar problem trying to execute the examples from the network docs. If I enable the network inspect, everything works ok, but on release, the fetch hangs and don't even give me an error. I can reproduce the error following the steps:

    1. npx react-native init AwesomeProject
    2. Add a Button with the fetch call inside onPress event

    Tested using react-native 0.63.4 and 0.62.2

  19. danmaas commented on Dec 6, 2020

    @danmaas

    Not sure if this is relevant, but I hit an issue a few weeks ago where connections to IPv6 addresses would fail silently in the OkHTTP library on one device I had. Telling OkHTTP to prioritize IPv4 over IPv6 fixed it.

  20. cristianoccazinsp commented on Jul 21, 2021

    @cristianoccazinsp
    Contributor

    @danmaas how do you "tell OkHTTP" to prioritize IPv4 from react native?

  21. danmaas commented on Jul 21, 2021

    @danmaas

    @cristianoccazinsp Here is a Gist with the relevant code excerpt:

    https://github.com/proxy/gist.github.com/danmaas/c60af5fed9f55d2bc616ce302696540d

    This overrides the default OkHTTP client factory with a shim that intercepts DNS resolutions and sorts the result list to return IPv4 addresses before IPv6 addresses.

  22. locked as resolved and limited conversation to collaborators on Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions