Skip to content

Abort works incorrectly for delayed requests #162

@iyarkov

Description

@iyarkov

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions