0

Has anyone seen this bug with AngularJS (v1.0.7) and Chrome (Version 30.0.1599.114) where canceling http GET request puts the sockets into a pending state thus maxing out the thread pool in chrome?

Code:

             if ($scope.canceler !== undefined) {
             $scope.canceler.resolve();
             $scope.canceler = undefined;
         }
         $scope.canceler = $q.defer();

         $http.get("/apicall", {
             cache: myCache,
             timeout: $scope.canceler.promise
         }).success(function (results) {

         }).
         error(function (result) {

         });

enter image description here

Might be the same bug 241844

TheHippo
  • 61,720
  • 15
  • 75
  • 100
Dimitry
  • 4,503
  • 6
  • 26
  • 40

1 Answers1

3

You should update AngularJS to 1.1.5 to be able to cancel http calls. ref: In AngularJS, how to stop ongoing $http calls on query change

Here is the working code and the JS fiddle. I have tested with AngularJS 1.2.0 and Chrome 32.0.1700.0 canary.

function Ctrl($rootScope, $scope, $http, $q, $timeout) {
    var canceler = $q.defer();

    console.log("Calling...");
    $http.get("/echo/json", {
        //Will return data after 5 seconds passed
        data: {json: {id: "123"}, delay: 5},
        timeout: canceler.promise
    }).success(function (results) {
            console.log("Success");
            console.log(results);
        }).
        error(function (result) {
            console.log("Error");
            console.log(result);
        });

    $timeout(function () {
        console.log("1 second passed");
        // now, cancel it (before it may come back with data)
        $rootScope.$apply(function () {
            console.log("Canceling..");
            canceler.resolve();
        });
    }, 1000);
}

http://jsfiddle.net/7Ma7E/4/

The request was become cancelled state.

Requests become cancelled

Community
  • 1
  • 1