question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout ignored on Android devices

See original GitHub issue

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]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:22
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
teckel12commented, Apr 6, 2020

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);
            });
7reactions
camillaferrericommented, Oct 7, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix: Screen Timeout Not Working After Android 12 update
Fix: Screen Timeout Not Working After Android 12 update · Head over to the Settings menu on your device > Go to Apps...
Read more >
Why screen timeout is not working? | Finddiffer.com
Method to Fix screen timeout not working after the Android 12 update. Try to clear the 'Settings' and 'Settings Services' app and then...
Read more >
Android phone ignores screen timeout setting - help! | [H]ard
Reports of Android phones ignoring whatever their screen timeout setting ... Location of screen timeout setting: Settings / Display / Sleep
Read more >
Axios timeout not working as expected on limited hotspot
Now if I place an HTTP using above axios configuration, it never times out after 30 seconds for Android devices. But for iOS...
Read more >
Fix Screen Timeout Not Working After Android 12 update
Try to clear the 'Settings' and 'Settings Services' app and then reboot the device. Check for the issue again. For doing this: Go...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found