axios: Timeout ignored on Android devices

Describe the bug Trying to send a request (no matter what) the timeout will be ignored and is alway 5000ms. The corresponding error gives the correct value in console e.g. “timeout of 30000ms exceeded” but it was actually 5000ms. On IOs everything is working fine. Try to set the timeout for default config and for each request. Same behavior.

const header = {
  Authorization: myToken,
};

const defaultConfig = {
  baseURL: url,
  timeout: 30000,
  headers: header,
};

return axios.create(defaultConfig);

Expected behavior The Timeout will be thrown after the defined timeout on Android devices

Environment:

  • Axios Version [0.18.0]
  • Android Version [9.0, 8.0]
  • React Native Version [0.59.1]

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 24
  • Comments: 21 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve been forced to use cancelToken and a JavaScript timeout as a replacement to defaults.timeout which doesn’t work on all platforms. Here’s sample code for those who are still having this problem a year after it was reported:

        let axiosCall = axios.CancelToken.source();
        setTimeout(() => { axiosCall.cancel(`Timeout of 3000ms exceeded`) }, 3000);
        axios({
                method: 'post',
                cancelToken: axiosCall.token,
                url: 'https://blablabla.com/route',
                data: {
                    // Your data to send here
                }
            })
            .then(({ data }) => {
                // Success
            })
            .catch((err) => {
                console.log(err.message);
            });

I was experiencing the same problem on Android using RN. I solved the problem by adding:

<application
  ...
  // add this
  android:usesCleartextTraffic="true">

in my AndroidManifest.xml

Seems like from Android 9 it blocks any call not in https. Here’s more info.

I solved the problem by adding timeout into the axios configuration before data parameter. For some reason, timeout parameter will not work if placed after the data parameter.

axios({
      method: 'post',
      timeout: 1000,
      url: 'http://192.168.0.1:5000/download',
      data: {
          access: data.token
      }
})
.then(function (response) {
    alert(response.data);
})
.catch(function (error) {
    alert("There was an error in communicating to server");
});

Is it really possible this is still a bug a year later? I’m still experiencing this as well on Android (React Native) only.

Same for me, RN 0.59.9 and axios 0.19.0. Timeout always works on iOS devices, but on Android it’s completely unreliable. It works just sometimes and it stops working without changes on the code.

Hi @paritosh-yadav I am adding it to axios-next so that we can look at it in the next version after the 0.22

+1, same for me, RN 0.59.5 and axios 0.19.0, works on iOS but not on android

I have executed request about 14000ms. But I have received error message “timeout of 90000ms exceeded” (timeout = 90000). This issue only display in Android but IOS is normal.