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

Ajax angular HTTP request are not aborted as expected #8468

Merged
merged 2 commits into from Aug 17, 2015

Conversation

Projects
None yet
2 participants
@tsteur
Member

tsteur commented Jul 30, 2015

While working for a fix of #7692 in #8467 I noticed that Piwik API requests made via angularjs were never really aborted. You can reproduce this by opening the website selector, then type many letters quickly. You will notice in the network tab of developer tools that the requests are not aborted. They are all finished and it slows down all the requests.

The only way the aborting of requests worked was to call deferred.resolve() instead of deferred.reject(). I presume this is because the $http timeout config that is used to cancel a request only listens to the success callback here: https://github.com/angular/angular.js/blob/v1.2.28/src/ng/httpBackend.js#L136 . When calling reject() it won't trigger the success callback and won't abort the HTTP request.

It used to work via resolve() but was changed to reject() here: 2b72250

@tsteur tsteur added this to the 2.15.0 milestone Jul 30, 2015

@tsteur tsteur changed the title from fix abort does not actually abort a request to Fix regression abort angular HTTP request does not work anymore Jul 30, 2015

@@ -105,32 +118,32 @@
headers: headers
};
$http(ajaxCall).success(onSuccess).error(onError);
var promise = $http(ajaxCall).then(onSuccess, onError);

This comment has been minimized.

@tsteur

tsteur Jul 30, 2015

Member

We should not use requestPromise but promise as requestPromise gets never cancelled and we would go into success callback of any promise instead of the error callback when a request is aborted

@tsteur

tsteur Jul 30, 2015

Member

We should not use requestPromise but promise as requestPromise gets never cancelled and we would go into success callback of any promise instead of the error callback when a request is aborted

},
abort: function () {
deferred.reject();
deferred.resolve();

This comment has been minimized.

@tsteur

tsteur Jul 30, 2015

Member

Here we make sure to actually abort the request

@tsteur

tsteur Jul 30, 2015

Member

Here we make sure to actually abort the request

tsteur added a commit that referenced this pull request Aug 17, 2015

Merge pull request #8468 from piwik/fix_abort_http_request
Fix regression abort angular HTTP request does not work anymore

@tsteur tsteur merged commit 7bc1f1f into master Aug 17, 2015

1 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/travis-ci/push The Travis CI build failed
Details
Scrutinizer No new issues
Details

@tsteur tsteur deleted the fix_abort_http_request branch Aug 17, 2015

@mattab mattab changed the title from Fix regression abort angular HTTP request does not work anymore to Ajax angular HTTP request are not aborted as expected Oct 13, 2015

@mattab mattab added the Bug label Oct 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment