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

Neither then() nor catch() executed when request timeout in Safari #294

Closed
fabioberger opened this issue Mar 11, 2016 · 5 comments · Fixed by #306
Closed

Neither then() nor catch() executed when request timeout in Safari #294

fabioberger opened this issue Mar 11, 2016 · 5 comments · Fixed by #306

Comments

@fabioberger
Copy link

In Safari V9.0.3 (10601.4.4), neither then() nor catch() is called when a request timeout occurs. Instead, Safari prints out the following error to the console:

screen shot 2016-03-11 at 3 43 22 pm

In Chrome V49.0.2623.87 (64-bit), the catch() callback is properly executes as expected.

Test Script Used:

fetch('http://10.255.255.1') // a non-routable IP address
    .then(function(response) {
        console.log("response.ok", response.ok);
    }).catch(function(error) {
        console.log('Failed: ', error)
    });

Without either then() or catch() being called on timeout, how are we supposed to handle this type of request failure for Safari browsers?

@mislav
Copy link
Contributor

mislav commented Mar 12, 2016

Thanks for bringing this to our attention. This seems to be a limitation of XMLHttpRequest in Safari. I'm not sure if there's something we can do about this, but on your end you can definitely install an ad-hoc timeout like suggested here. This will at least ensure that non-routable requests eventually get rejected.

@fabioberger
Copy link
Author

Thanks for the quick response Mislav, I've gone ahead and filed a bug report for the Safari team at Apple and in the mean time will implement the timeout as you suggested.

@dgraham
Copy link
Contributor

dgraham commented Mar 12, 2016

@mislav I think this is asking for:

xhr.ontimeout = function() {
  reject(new Error('timeout'))
}

so that the promise is not trapped in the pending state.

@fabioberger What is the error object returned by Chrome and Firefox in your catch example?

@fabioberger
Copy link
Author

@dgraham The error returned from the catch in Chrome is:

TypeError: Failed to fetch
    at TypeError (native)

Full console output:

screen shot 2016-03-12 at 1 03 38 pm

dgraham added a commit that referenced this issue Apr 1, 2016
Firefox and Chrome trigger the request's `onerror` handler when a
timeout occurs. Safari triggers the `ontimeout` handler.

This can be observed by making a request to an unroutable address:

    var xhr = new XMLHttpRequest()
    xhr.onload = console.log.bind(console, 'loaded')
    xhr.onerror = console.log.bind(console, 'errored')
    xhr.ontimeout = console.log.bind(console, 'timeout')
    xhr.open('GET', 'http://10.255.255.1')
    xhr.send()

Fixes #294.
mislav pushed a commit that referenced this issue May 5, 2016
Firefox and Chrome trigger the request's `onerror` handler when a
timeout occurs. Safari triggers the `ontimeout` handler.

This can be observed by making a request to an unroutable address:

    var xhr = new XMLHttpRequest()
    xhr.onload = console.log.bind(console, 'loaded')
    xhr.onerror = console.log.bind(console, 'errored')
    xhr.ontimeout = console.log.bind(console, 'timeout')
    xhr.open('GET', 'http://10.255.255.1')
    xhr.send()

Fixes #294.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@mislav @dgraham @fabioberger and others