Repository navigation
Network requests silently fail in Android since v0.63.0 #29608
Copy link
Copy link
Closed
Labels
Platform: AndroidAndroid applications.Android applications.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
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
- Install the last known good version:
npx react-native init AwesomeProject --version 0.62.2- Replace the contents of
App.jswith one of the examples from the network docs, e.g., the Fetch Example. - Run the application in iOS.
npx react-native run-ios- Note that the fetch example displays as intended.
- Run the application in Android.
npx react-native run-android- Note that the fetch example displays as intended.
- Install latest (v0.63.2 as of this report):
npx react-native init AwesomeProject- Replace the contents of
App.jswith one of the examples from the network docs, e.g., the Fetch Example. - Run the application in iOS.
npx react-native run-ios- Note that the fetch example displays as intended.
- Run the application in Android.
npx react-native run-android- 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:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Platform: AndroidAndroid applications.Android applications.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Activity
scobo commentedon Aug 10, 2020
Fixed Snack link: https://snack.expo.io/2HgnLjyI_
scobo commentedon Aug 10, 2020
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.
safaiyeh commentedon Aug 11, 2020
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?
scobo commentedon Aug 12, 2020
This was 100% repro for us and now it’s zero. I have no idea what was wrong.
scobo commentedon Aug 12, 2020
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.scobo commentedon Aug 12, 2020
100% repro with the following steps.
npx react-native foobar --version 0.63.2cd foobarnpx react-native run-androidApp.jscontents with fetch example (see Snack link above).Rin Metro console.Ctrl+Cto shut down Metro and close window.cd .. && rm -rf foobarscobo commentedon Aug 12, 2020
Same result on iOS now.
Flipper indicates the request was successful and I can inspect the response there, but
isLoadingistruein the app anddatais an empty array.13 remaining items
scobo commentedon Aug 26, 2020
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.
scobo commentedon Aug 26, 2020
Ran into a separate issue when trying to repro with an earlier version: #29781
snowloop commentedon Aug 27, 2020
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
scobo commentedon Aug 28, 2020
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.scobo commentedon Aug 31, 2020
From macOS, with both a Pixel 2 emulator and a Pixel 4 device:
npx react-native init AwesomeProjectcd AwesomeProjectnpx react-native run-androidApp.js.Rfrom Metro consoleFrom Ubuntu 18.04, with both a Pixel 3 emulator and a Pixel 4 device:
npx react-native init AwesomeProjectcd AwesomeProjectnpx react-native run-androidnpx react-native start(run-androiddoesn’t seem to automatically launch Metro in Ubuntu.)App.js.Rfrom Metro consoleFlipper indicates the network request was successful. Closing Flipper and refreshing the app has no affect on the outcome.
scobo commentedon Aug 31, 2020
@yungsters Can you try to repro by invoking
react-nativevia Yarn?npx react-native init AwesomeProjectcd AwesomeProjectyarn react-native startyarn react-native run-androidWe repro’d on a “clean” machine which was able to run the fetch example successfully via
npx. Subsequently invokingyarn react-native startseemed to “poison“ the machine and network requests would no longer work (on emulators or devices), even after switching back tonpx react-native.scobo commentedon Aug 31, 2020
More info: If we invoke Metro via
yarnin our monorepo, it seems to “poison” the Metro cache. Runningyarn react-native --reset-cachein 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-androidworks but notnpx react-native run-android --variant=release.Edit: Running a release build also appears to “poison” the Metro cache.
scobo commentedon Sep 2, 2020
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.
higoramp commentedon Dec 6, 2020
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:
Tested using react-native 0.63.4 and 0.62.2
danmaas commentedon Dec 6, 2020
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.
cristianoccazinsp commentedon Jul 21, 2021
@danmaas how do you "tell OkHTTP" to prioritize IPv4 from react native?
danmaas commentedon Jul 21, 2021
@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.