fix: set network timeout duration for whole the call operation#29471
fix: set network timeout duration for whole the call operation#29471krizzu wants to merge 1 commit into
Conversation
Base commit: 91d16bb |
Base commit: 91d16bb |
|
This is a duplicate of #28491 . Is this going to get merged? Would highly appreciate some attention for this issue |
|
Any updates? |
LironSherk
left a comment
There was a problem hiding this comment.
had the same issue, will solve the bug
|
Perhaps Im new... but what is the CircleCI test_windows trying to do? |
|
Can confirm that we're also affect by the same issue and that this PR fixes it. |
|
Or is there anyway tha tI can run from this branch? Because i tried pointing to the branch in my package.json, but it seems like it is not getting changes from class |
|
If anyone need those changes now in their codebase, you can use patch-package to apply this fix. Note: This will only work if you build React Native locally, so that you can apply changes to your React Native module itself. Here's the guide how could you go about building from source How it works
How to use it
|
@krizzu tried the suggested but apparently this is a I realised that if by just looking at the For instance the react-native version in Wondering how did you manage to do that? did you rebuild the |
Exactly, per default gradle doent build the react-native android native modules but downloads them from a remote repository. We patched the java code and used these instructions for building the native modules from node_modules. It wasn't super straightforward, but if you run into issues, I can try to help |
|
@MystL My apologies and You're right - Android comes already pre-build, so this patch-package won't work directly. I remember now that what we did to make this work was instead copying over the Networking module implementation, including it as a new native module and patch-packaged the So either building from source + patching the change OR one could also go around and modify the OkHttp client timeout values via builder instead. For example, in your @Override
protected List<ReactPackage> getPackages() {
// ....
NetworkingModule.CustomClientBuilder builder = new NetworkingModule.CustomClientBuilder() {
@Override
public void apply(OkHttpClient.Builder builder) {
// play with values, 0 means no timeout
builder.callTimeout(30000, TimeUnit.MILLISECONDS);
builder.readTimeout(0, TimeUnit.MILLISECONDS);
builder.writeTimeout(0, TimeUnit.MILLISECONDS);
builder.connectTimeout(0, TimeUnit.MILLISECONDS);
}
};
NetworkingModule.setCustomClientBuilder(builder);
return packages;
}
Actually, I see this will be fine, since |
|
Two years later, it's still not resolved. |
|
This PR 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. |
|
Does it still valid? |
Summary: This PR is a continuation of this #29471. All context you can find here: axios/axios#2073 (comment) axios/axios#2073 (comment) ## Changelog: [ANDROID] [FIXED] - change `connectTimeout` to `callTimeout` in OKHttp client Pull Request resolved: #38953 Test Plan: - Throttle internet connection (You can use GSM one) ``` import axios from "axios"; axios.get('https://jsonplaceholder.typicode.com/users', { timeout: 5000 }) .then(response => { console.log(response.data); }) .catch(error => { if (error.code === 'ECONNABORTED') { console.log('Request timed out'); } else { console.log(error.message); } }); ``` **Expected result** `Request timed out` should be visible in a console **Videos** Before https://github.com/facebook/react-native/assets/12766071/03a3d666-6a27-4d67-bc68-6bcf6e908e19 After https://github.com/facebook/react-native/assets/12766071/2650d02d-640c-43fe-b1e8-baeac78870f2 **Example URL** Branch: https://github.com/troZee/react-native/tree/fix/network-timeout-example Commit: https://github.com/troZee/react-native/commit/e255e1a423143c4bd4f3e37656a56ba2ecbbf3e2 Reviewed By: mdvacca Differential Revision: D48414884 Pulled By: NickGerleman fbshipit-source-id: 86324601f7459c154b5fc879f8b773df4901f6e0
|
Someone tried to solve this problem since I have the same problem, when using axios in react native the timeouts in the requests do not work correctly when I am on an unstable network, I perform the cancellation by token or using abortcontroller but when I recover again the connection, future requests are no longer made until I restart the app |
|
Well done @troZee 🎉 |
Summary
Networking module for Android has been incorrectly setting
timeoutduration - the value has been set only for the duration of the connection to the host, instead of the whole network operation (sending/reading body). Because of that, the long standing API call would timeout, even though the default value of timeout is 0ms (no timeout) (for axios, it's the cryptic "Timeout of 0ms exceeded" error). That happens becauseOkHttp(used for networking under the hood) has default values of 10s for writing/reading operation, which are not changed.This PR fixes that by applying the value of timeout for the whole operation.
Thanks @wojteg1337 for help to nail down the root of the issue 💪
Changelog
[Android] [Changed] - Correctly set timeout for network calls
Test Plan
Green CI.