Skip to content

Commit

Permalink
fix: network call timeout (#38953)
Browse files Browse the repository at this point in the history
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:
troZee@e255e1a

Reviewed By: mdvacca

Differential Revision: D48414884

Pulled By: NickGerleman

fbshipit-source-id: 86324601f7459c154b5fc879f8b773df4901f6e0
  • Loading branch information
troZee authored and facebook-github-bot committed Sep 10, 2023
1 parent 17ecae9 commit e00f244
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ public void onProgress(long bytesWritten, long contentLength, boolean done) {
// client and set the timeout explicitly on the clone. This is cheap as everything else is
// shared under the hood.
// See https://github.com/square/okhttp/wiki/Recipes#per-call-configuration for more information
if (timeout != mClient.connectTimeoutMillis()) {
clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
if (timeout != mClient.callTimeoutMillis()) {
clientBuilder.callTimeout(timeout, TimeUnit.MILLISECONDS);
}
OkHttpClient client = clientBuilder.build();

Expand Down

0 comments on commit e00f244

Please sign in to comment.