You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
CLI:
Cross-platform modules: 4.2.1
Android Runtime: 4.2.0
iOS Runtime: -
Plugin(s): -
Describe the bug
I try to set a timeout for our http requests in our NativeScript app, but the timeout property has no effect for me while testing.
The provided url leads to a sample webservice from https://www.mocky.io/ and the delay is set to 10 seconds.
Open the provided sample app and tap the button.
It will start the http request and after about 10 seconds, you get an alert with the json response.
Expected behavior
Setting the timeout to 5000 ms, I would expect, that the http request was canceled and that I would get to the failure part of the Promise.
Additional context
Maybe I am misunderstanding the sense of the timeout property.
The reason for me setting this property:
I want to prevent, that the user waits for a long time to get the response of an http request. Instead there should be a 'maximum' time (i.e. 10 seconds) for the user to wait and when this time has passed, the loading indicator should be hidden and it should ignore the response of this request, if it is received later.
Is this not the function of the timeout property?
Hi @felix-idf,
Thank you for the provided sample project.
It seems that there is an issue with the HTTP module while using the timeout option. I was able to recreate the problem only on Android. On iOS, the timeout works as expected. I will mark this as a bug and would suggest keeping track on the issue for further info.
Turned out that the above mentioned workaround wasn't sufficient for our requirements because only connect timeout is set for the HttpURLConnection in org.nativescript.widgets.Async's HttpRequestTask. Setting read timeout provided the desired result, that is, causing the timeout to expire when no data is received within the timeout period. So, as has also been suggested in this issue, I'd consider setting read timeout in addition to connect timeout:
Activity
tsonevn commentedon Nov 8, 2018
Hi @felix-idf,
Thank you for the provided sample project.
It seems that there is an issue with the HTTP module while using the timeout option. I was able to recreate the problem only on Android. On iOS, the timeout works as expected. I will mark this as a bug and would suggest keeping track on the issue for further info.
Erudition commentedon Aug 29, 2019
For the XMLHttpRequest, it seems that "timeout" is not even a supported event, which is causing my app to crash. I'd love to have this working!
NativeScript/tns-core-modules/xhr/xhr.ts
Line 168 in c7d4b99
NativeScript/tns-core-modules/xhr/xhr.ts
Line 169 in c7d4b99
NativeScript/tns-core-modules/xhr/xhr.ts
Line 170 in c7d4b99
SpurguX commentedon Nov 12, 2019
I had a similar problem when I tried to set a timeout for axios requests. I used the workaround provided by Manoj in this post: https://stackoverflow.com/questions/58767691/timeout-feature-in-axios-has-no-effect-in-a-nativescript-vue-environment
SpurguX commentedon Nov 19, 2019
Turned out that the above mentioned workaround wasn't sufficient for our requirements because only connect timeout is set for the HttpURLConnection in org.nativescript.widgets.Async's HttpRequestTask. Setting read timeout provided the desired result, that is, causing the timeout to expire when no data is received within the timeout period. So, as has also been suggested in this issue, I'd consider setting read timeout in addition to connect timeout:
jarmani commentedon Dec 9, 2019
@SpurguX We have gone to the same conclusion today after infinite loading on Android but not iOS. Our patch is the same as yours and fix it.
@tsonevn What can be done to advance on this one ? This bug is pretty anoying. Thanks.
fix(android): Request Timeout NativeScript#6523
fix(android): Request Timeout #6523 (#8194)