react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Networking] socket error EINPROGRESS sometime appear using fetch on some Android devices

Open Aure77 opened this issue 5 years ago • 5 comments

Description

I got sometime a Network Request Error when using fetch on Samsung Ax phones on Android 10 only (1 request / 3 fail). After debugging native code (NetworkingModule), an exception is raised by OkHttp client (into okhttp3.internal.connection.RealConnection.connectSocket) with android.system.ErrnoException: connect failed: EINPROGRESS (Operation now in progress). After some research I found a post that talk about this android issue on Samsung device: https://www.softax.pl/blog/solved-samsung-a70-problems-after-upgrade-to-android-10-do-i-have-to-wait-for-samsung-to-help-my-app-users/

This developer says that the error occur when connectTimout is set to 0 ms when opening a socket connection.

By default OkHttp client builder use 10 000ms connectTimeout: https://github.com/square/okhttp/blob/06d38cb795d82d086f13c595a62ce0cbe60904ac/okhttp/src/main/java/okhttp3/OkHttpClient.java#L494 But React Native OkHttp client provider override default timeout for request setting them to 0 ms: https://github.com/facebook/react-native/blob/aee88b6843cea63d6aa0b5879ad6ef9da4701846/ReactAndroid/src/main/java/com/facebook/react/modules/network/OkHttpClientProvider.java#L66-L68

There is no way to set timeout from JS side nor native side, because it's hard coded in RN XMLHttpRequest: https://github.com/facebook/react-native/blob/0b9ea60b4fee8cacc36e7160e31b91fc114dbc0d/Libraries/Network/XMLHttpRequest.js#L121

So there is a reason that socket timeout are set to 0 in React Native network module ?

It will be good think to allow users to customize their http/socket timeout. Either by a global settings on a network manager, ex: XMLHttpRequest.setTimeout(10000); // statically or some other way or by request through fetch option, ex: fetch('/my/url', { timeout: 10000 });

React Native version:

System: OS: macOS 10.15.5 CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz Memory: 26.50 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.13.1 - /var/folders/dk/00snz9k93s16_9x8yg4tpxp40000gn/T/yarn--1595497465154-0.37374595055775384/node Yarn: 1.22.4 - /var/folders/dk/00snz9k93s16_9x8yg4tpxp40000gn/T/yarn--1595497465154-0.37374595055775384/yarn npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 IDEs: Android Studio: 3.6 AI-192.7142.36.36.6392135 Xcode: 11.5/11E608c - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.4 => 0.61.4

Steps To Reproduce

Make multiple fetch (async) on a Samsung Ax phone with Android 10

Expected Results

This error should not be raised OR/AND connectTimeout should be overridable through react native.

Aure77 avatar Jul 23 '20 12:07 Aure77

cc @dulmandakh

safaiyeh avatar Aug 05 '20 17:08 safaiyeh

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Dec 26 '20 01:12 stale[bot]

How can I label this issue ? I have no rights on it.

Aure77 avatar Dec 26 '20 05:12 Aure77

I have same issue. I use axios lib to send a post request. android will display network error (timeout error message) when response duration time > 10s (default OkHttp client builder use 10 000ms connectTimeout)

https://github.com/facebook/react-native/pull/28491 <-- I have try this change, but also cannot fix the issue.

anyone have solution ?

LouisLeung avatar Aug 19 '22 03:08 LouisLeung

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[bot] avatar Jun 15 '23 05:06 github-actions[bot]

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

github-actions[bot] avatar Jun 22 '23 05:06 github-actions[bot]