[Android] - XMLHttpRequest ontimeout not fired
See original GitHub issueTimeouted XMLHttpRequest request do not call the timeout callback on android. The request is being aborted (the onreadystatechange or onerror never get called after) while in IOS the timeout event getting called as expected.
const request = new XMLHttpRequest();
request.open('GET', "http://localhost:3333/", true);
request.timeout = 1000;
request.onabort = () => { console.log('abort', request); };
request.onerror = () => { console.log('error', request); };
request.onload = () => { console.log('load', request); };
request.onloadend = () => { console.log('loadend', request); };
request.onreadystatechange = () => { console.log('onreadystatechange', request); };
request.ontimeout = () => { console.log('ontimeout', request); };
request.send();
The server sleeps for 3 seconds to make sure the timeout occurs.
will print on Android
onreadystatechange XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
load XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
loadend XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
on Ios
onreadystatechange XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
ontimeout XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
loadend XMLHttpRequest {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4…}
Additional Information
- React Native version: 0.39.2
- Platform: Android
- Operating System: MacOS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
XMLHttpRequest.timeout - Web APIs - MDN Web Docs
When a timeout happens, a timeout event is fired. Note: You may not use a timeout for synchronous requests with an owning window....
Read more >Timeout XMLHttpRequest - Stack Overflow
I want it to display text as "Timed Out". var bustcachevar = 1 //bust potential caching of external pages after initial request? (1=yes,...
Read more >XMLHttpRequest timeout ignored - Fuse Community
Just noticed that XMLHttpRequest is ignoring the timeout property on Fuse, I'm running version 1.0.1 (build 13566) on Windows 10 here.
Read more >XMLHttpRequest.timeout - Web APIs
The XMLHttpRequest.timeout property is an unsigned long representing the number of milliseconds a request can take before automatically being terminated.
Read more >XMLHttpRequest timeout - Chrome Platform Status
Exposing the XHR timeout property and sending corresponding events ... Status: Specification currently under development in a Working Group ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I solved this problem with a setTimeout method. If the readyState is not DONE, call the request.abort() function.
Thanks @Lxxyx This is a specific workaround using axios but it probably should have a fix in the android code. this bug will persistent for different libraries as well.
@Lxxyx In the gist provided you always overriding the cancelToken, that mean you won’t be able to cancel requests that are not timeouted (Which is probably one of the reasons you are using axios instead of fetch in the first place), you can solve this by creating a wrapper around every request that will generate the cancel token and pass it (Not using the axios interceptors) or by passing cancelExecuter inside the config object and before generating a new cancel token, check if one already exsists.