[Networking] socket error EINPROGRESS sometime appear using fetch on some Android devices
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.
cc @dulmandakh
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.
How can I label this issue ? I have no rights on it.
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 ?
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.
This issue was closed because it has been stalled for 7 days with no activity.