Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout value is defined but not honored #7

Open
briandeanda opened this issue Jun 20, 2017 · 12 comments
Open

Timeout value is defined but not honored #7

briandeanda opened this issue Jun 20, 2017 · 12 comments

Comments

@briandeanda
Copy link

briandeanda commented Jun 20, 2017

For example, if I set a timeout of 2000, the network call does not error out and xhr.ontimeout is never called. When I log the values of init i can see that timeout is defined, I can also see that the xhr.timeout is set.
This happens on a Motorola Moto E2 Android 5.1, API 22 with React Native 0.45.1

@cikai
Copy link

cikai commented Jun 26, 2017

@briandeanda I have the same problems, timeout xhr.onerror is only called when I change my network status, for example, close wifi or switch to other wifi .

@dcarrot2
Copy link

@cikai Keep us updated if you find a workaround.

@vipcxj
Copy link

vipcxj commented Nov 14, 2017

facing the same problem!

@rafkhan
Copy link

rafkhan commented Jan 3, 2018

Does this only happen on android?

@pstanton
Copy link

pstanton commented Feb 5, 2018

+1 running android on galaxy s5

@pstanton
Copy link

pstanton commented Feb 8, 2018

I think XMLHttpRequest is implemented by react native and doesn't support the timeout feature. Therefore, a different mechanism is required to add timeout. Therefore this project is X|

@pstanton
Copy link

pstanton commented Feb 8, 2018

a working solution: JakeChampion/fetch#175 (comment)

@atticoos
Copy link
Contributor

atticoos commented Feb 8, 2018

I've had trouble reproducing this and could use help tackling it down and curious if later versions of React Native. I'm a bit at a loss, as timeouts have been supported natively since v0.19

@pstanton:

I think XMLHttpRequest is implemented by react native and doesn't support the timeout feature. Therefore, a different mechanism is required to add timeout. Therefore this project is X|

Yes, while React Native does implement XMLHttpRequest, it accepts a timeout and provides that to the native APIs (iOS, Android)

a working solution: JakeChampion/fetch#175 (comment)

The downside of JakeChampion/fetch#175 (comment) is that it doesn't cancel the corresponding native request http request. Rather, on the client side, it just rejects the caller's promise. While it can be considered a work around if you aren't concerned by that, it's not a true timeout that many of us are looking for.

@pstanton
Copy link

pstanton commented Feb 8, 2018

Hi Aj, thanks for the attention. I'm currently using "react-native": "0.51.0" and a samsung galaxy s5 to test over adb (usb cable).

that is running android 7.0

I've tested with and without the chrome debugger attached (this can change behaviour).

Agree with downside of wrapping a timeout. A better solution would be great. If the http request is never cancelled, and never times out, is that an open socket until the app is completely closed?

personally i can't believe this very basic feature is missing from the stack! hence why so many projects like yours exist.

would be great if i can get it to work. cheers!

@atticoos
Copy link
Contributor

atticoos commented Feb 8, 2018

Thanks for the environment info 👍

If the http request is never cancelled, and never times out, is that an open socket until the app is completely closed?

There's supposed to be a global default timeout on all connections. However, we were running an earlier version of React Native when putting this together because we noticed requests seemed to hang indefinitely, and then during a network change event, they would then all come back and resolve/reject.

@ithieund
Copy link

Maybe I faced with the same problem.

  • When I fetch a right url, the timeout with 10 seconds works OK
  • But when I try with incorrect url, the request hangs for a long time (2 or 3 mins) and finally return with error message in the console: 'HTTP error:', [TypeError: Network request failed]

How can we make this case jump into catch() after timeout was reached?

@TuurDutoit
Copy link

I was faced with the same issue, and after a long search I found out what was going wrong. The timeout option that React Native provides for XMLHttpRequest (which is used under the hood by this package), is actually a connect timeout, i.e. it is the time from the moment that the request was dispatched (the fetch() call) and the moment that the TCP connection was established. From that point on, the timeout is no longer relevant. In other words, React Native will wait for the server's response as long as needed, essentially ignoring the timeout option, as long as the initial TCP connection succeeded within the timeout duration.

This is at least true for Android - I think the iOS implementation is more sensible, but I didn't investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants