错误地被激活$ http.post不止一次
编辑:
我可能会问错误的问题。 我今天上午简化了Node.js代码,问题停止了。 这个问题似乎与使用deasync模块有关:
var done = false; processGridCell(cell, layers, rowCount, colCount, datasetObject, function() { done = true}); deasync.loopWhile(function(){ return !done });
我猜deasync是用来防止function内存不足。 每次调用processGridCell都会保存一个MongoDB文档,它被称为〜12,000次。 因为主节点线程永远不会产生asynchronousmongoose.save +callback的时间,所以被保存的对象从不被GCC处理,并且进程内存不足。
我没有看到使用deasync的简单方法。 我也不知道为什么使用deasync会导致客户端发出另一个POST请求,为什么删除它会阻止这个请求的发生。
我已经inheritance了一个节点/angular度应用程序,我已经负责修复了一下。
发生什么事是,当一个表单被提交时,它会调用一个Node.js函数,运行需要10-20分钟。 几分钟后,虽然我可以看到Node函数仍在运行,但是第二次从客户端提交相同的发布请求。 我没有能够找出原因。 另外,我在POST请求之前logging信息,但是它只logging第一次,而不是第二次。
这是代码,显着删节。
HTML:
<header class="text-center" data-ng-include="'/modules/core/views/header.client.view.html'"></header> <section> <div class="get-grid-form"> <h2>Input Grid Size</h2> <hr> <form name="gridSizeForm" ng-controller="gridSizeCtrl" data-ng-submit="submitGridInput()" ng-class="{'has-error': gridSizeForm.myDecimal.$invalid}" > <div class="grid-input-form"> <p>Other Irrelevent Content</p> <div class="get-grid-form-button" ng-show="!isLoading&&isCalculating&&!isError"> <button type="submit" class="btn btn-primary" style="width: auto; margin: 2px;">OK</button> <button type="button" class="btn btn-primary" ng-show="!isLoading" ng-click="cancel()"style="width: auto; margin: 2px;">Cancel</button> </div> </div> </form> </div> </section>
angular度:
angular.module('module').controller('gridSizeCtrl', ['$scope', 'Upload', '$http', '$window', '$stateParams', '$location', function ($scope,Upload,$http,$window,$stateParams,$location) { $scope.submitGridInput = function() { if ($scope.cellwidth === 'default') { units = 'kilometers'; cellwidthval = 1; } $scope.upload( $scope.cellwidth, units, cellwidthval, $location.search()['param']); }; $scope.upload = function (cellwidth,units,widthval, params) { $scope.isLoading = true; console.log("This only logs once. The second request fires without this logging") $http.post('/module/grid/create', { data:{someData: someData} }).success(function(response) { //success code }).error(function(response) { //error code }); }; }
节点:
function moduleGridCreateFunction(req, res) { try { mongoose.find( function(err) { mongoose.save(function(err) { mongoose.save(function(err) { //etc. etc. etc. if(err) { res.status(400).jsonp('some error'); } else { //do thing that takes 10 minutes res.status(200).jsonp('success'); } }); }); }); } catch(err) { res.status(400).jsonp('error'); } }
- 使用Express / Node.js和Angular处理已取消的请求
- 奇怪的请求在Mean.io中重复
- Node.js从服务器渲染大量的JSON数据
- 什么是使用客户端路由的正确方法?
- 部署生产MEAN Stack应用的准则
- 无法在typescript / angular2环境中设置持久会话,在后端设置nodejs
- 使用node.js和socket.io进行套接字authentication(使用DaftMonk的generator-angular-fullstack)
- Express.js应用程序尝试使用angular度:未捕获错误:和未捕获错误:
- 将单页面Angular App模板集成到Sails.js中