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

Abort works incorrectly for delayed requests #162

Open
iyarkov opened this issue Mar 6, 2017 · 2 comments
Open

Abort works incorrectly for delayed requests #162

iyarkov opened this issue Mar 6, 2017 · 2 comments

Comments

@iyarkov
Copy link

iyarkov commented Mar 6, 2017

I'm submitting a bug report

  • Library Version:
    1.0.4

Please tell us about your environment:

  • Operating System:
    OSX 10.x

  • Browser:
    Chrome 56 | Firefox 51

  • Language:
    es2015

Current behavior:

An interceptor can delay XHR sending, and if the app cancels the request before it was send then the promise never resolved. HttpClient.pendingRequests collection grows with each request. Sample code:

initTest() {
    console.log('Test')
    this.testClient = new HttpClient();
    this.testClient.configure(config => {
        config.withInterceptor({
            request(message) {
                //Delay request for 1 second
                return new Promise((resolve, reject) => {
                    setTimeout(() => {resolve(message)}, 1000)
                })
            },
        });
    });
}

test() {
    console.log('Test')
    let promise = this.testClient.get('/test'); //preserve original promise with abort method
    promise.then(response => {
        console.log('response', response)
    })
    .catch(e => {
        console.log('error', e)
    })
    promise.abort()
    console.log('Pending requests', this.testClient.pendingRequests)
}

https://github.com/aurelia/http-client/blob/master/src/request-message-processor.js line 152 is invoked during processing phase.

if (this.isAborted) {
            // Some interceptors can delay sending of XHR, so when abort is called
            // before XHR is actually sent we abort() instead send()
            this.xhr.abort();
} else {

Line 140 - xhr.onabort = (e) => { never invoked

Expected/desired behavior:
Expected result - promise either resolved or rejected

@Alexander-Taran
Copy link

@iyarkov not really a solution to XHR problem, but fetch with abortController works right.
https://developer.mozilla.org/en-US/docs/Web/API/AbortController

@Alexander-Taran
Copy link

@bigopon maybe can be closed

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

3 participants