react-native: Fetching api response too slow when debugging mode is off

Description: Good evening guys, I am having an issue on my project on both android and iOS:

When i am using the app on debugging mode ON fetching data from api working pretty well, and getting the response just takes 2 seconds; When i am using the app debugging mode OFF fetching data from api takes more than 11 seconds, i wonder why, and its first time face this issue. I tried both Axios and Fetch both comes with the same results. Have anyone faces this issue before? Bonus: Postman and web-app getting response so fast like on debugging mode is ON

Code Example:

export const find = async (query: IFindQuery) => {
  const { apiServer } = getConfig();
  const queryString = stringify(query, {
    arrayFormat: 'brackets',
    encode: false,
  });
  const url = `${apiServer}/radiks/models/find?${queryString}`;
  const response = await fetch(url);
  return await response.json();
};

React Native version:

System: OS: macOS 10.15.3 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Memory: 113.79 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.14.1 - /usr/local/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.13.4 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 11.3/11C29 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5

Steps To Reproduce

  1. Using the app while debugging mode ON
  2. Using the app while debugging mode OFF

Expected Results

  1. Api response takes 2 seconds
  2. Api response takes 11 seconds

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 38

Most upvoted comments

@victoriaSh The ipv6 solution worked for you?

Yep! After setting up ipv6 for the domain that I’m using in fetch requests everything works fine. Still don’t get what exactly causes this behaviour. Guess there was a combination of 2 factors - my internet provider network settings + wrong IPv6 DNS settings for my domain. Try to make requests through mobile network or another internet provider. If it works fast that’s ipv6 settings problem.

Found a solution for my issue. Maybe it would be helpful for someone. Check IPv6 accessibility for the domain you trying to fetch from. https://ipv6-test.com/validate.php If web server is unreachable check your AAAA records, web server settings or ip6tables settings.

Having a similar issue. Although the fetch API is working fine on the web. On the app, the first fetch takes way too much time.

i did following

  • Wrote android native module to make http call. but it was also taking time for the first time.
  • Changed the region of aws ec2 to my nearest location. it reduced network latency by 3 times
  • did some testing using axios with retry and timeout. observed that First http always take time to establish connection and then subsequent response time of http call was negligible.

conclusion - It’s not react native specific issue . it’s platform specific (Android or ios).

Same issue on Android On react-native 63.3 about 8% of Android users were affected. On react-native 62.2 it’s about 3%. I don’t know if this is helpful information

same issue only ios. not always, it sometime

Having a similar issue. Although the fetch API is working fine on the web. On the app, the first fetch takes way too much time.

Same issue in android real devices for first api with https & working good in emulator

Same Here First API call takes around 11 seconds. Just a simple API call returns two string in a JSON as a response. The second call takes 1 to 2 seconds. Running Production App in android. What is causing this problem?