When using Angular $ q service, do promises final timeout yourself?
Some background: I have an Angular service that does POST to a remote server, which in turn queries the MySQL database and needs to send the result. Some queries return in less than a second, while others are expected to take up to 20 minutes. The problem is that exactly 4 minutes after sending the request, there is a network :: ERR_EMPTY_RESPONSE (in Chrome dev tools).
We use $ q and $ http in the service to facilitate POST.
queryDB: function(query, page) { var deferred = $q.defer(); $http.post(BASEPATH + "/filter", {data: query, page: page, token: localStorage.auth}, {timeout: 1200000}) .success(function(response) { deferred.resolve(response); }) .error(function(error) { deferred.reject(error); }) return deferred.promise; }
Here is the controller to which the promise is returned:
$scope.queryDB = function(page) { var query = formatQuery($scope.query); FilterService.queryDB(query, page).then(function(res) { ... })
I know that a call arrives at the server thanks to some simple logging. but what is strange to me is the dev console, which indicates that the connection is always "stalled" and never reached the server.
Again, this only happens when requests take more than 4 minutes, otherwise they behave normally. Therefore, I think Angular is not waiting long enough to allow / reject a promise. Is there any way to change this behavior?
source share