Abort works incorrectly for delayed requests
- Dominant language
- JavaScript
- Stars
- 60
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
**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
Contributor guide
Research direction
Start in src/request-message-processor.js around lines 140 and 152, then reproduce the delayed-interceptor example in Chrome or Firefox. Trace the abort path when XHR has not been sent yet; done means the original promise resolves or rejects and HttpClient.pendingRequests does not retain the cancelled request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100