Improper tracked[] element removal
Opened this issue · 0 comments
toddsmithwork commented
I ran into an issue where active() was returning false even though I had added a promise. The problem was due to the following sequence:
- call addPromise(myPromise)
- call cancel()
- myPromise.reject() // Fails even if you do this on step 2 due to cancel being synchronous and reject not
- addPromise(myPromise2)
What happens is onDone is called for myPromise which is not found in the tracked array, so index is -1. The splice operation removes something off the end of the array (which is myPromise2 at this point) when the index is -1
function onDone(isError) {
return function(value) {
(minDurationPromise || $q.when()).then(function() {
var index = tracked.indexOf(deferred);
tracked.splice(index, 1);
Should be:
function onDone(isError) {
return function(value) {
(minDurationPromise || $q.when()).then(function() {
var index = tracked.indexOf(deferred);
if (index != -1) {
tracked.splice(index, 1);
}