request.get上的Node.js零星“ECONNREFUSED”错误
我有一个零星的问题,我的节点/回送服务器。 我的设置如下:
编辑:我的节点版本是v4.2.4,我在Windows 10专业版上运行节点。
客户端:
-
nw.js客户端遍历本地文件系统并计算文件的MD5值。
-
使用
request.post
,客户端将文件的哈希以'fileHash: d41d8cd98f00b204e9800998ecf8427e'
的格式发送到服务器(这只是一个示例哈希,我知道这是一个空文件)function checkHash (fileHash){ request.post({ headers: {'content-type' : 'application/x-www-form-urlencoded'}, url: 'http://localhost:3000/api/checkBoths/hashcheck', method: 'POST', form: { fileHash: fileHash } }, function(error, response, body){ if(error) { console.log(error); } else { console.log(response.statusCode, body); } }); }
服务器端:
-
在
localhost:3000
运行的节点/环回服务器。 -
hashCheck
函数用于读取从客户端发布的数据,并查询用于匹配哈希的MySQL数据库。 -
来自服务器的响应格式为
goodResult : true
如果数据库中存在散列值,goodResult : false
如果不存在,goodResult : false
。var request = require('request'); module.exports = function (CheckBoth) { var goodResult; CheckBoth.hashCheck = function (fileHash, cb) { requestGood(fileHash); function requestGood (fileHash) { request.get('http://127.0.0.1:3000/api/Goodhashes/' + fileHash + '/exists', function (error, response, body) { if (!error && response.statusCode == 200) { goodResult = JSON.parse(body).exists; } if (error) { console.error(error); } }); console.log(goodResult); } cb( goodResult); }; CheckBoth.remoteMethod( 'hashCheck', { accepts: {arg: 'fileHash', type: 'string'}, returns: [{arg: 'goodResult', type: 'string'}] } ); };
问题:
服务器可以响应〜1000个查询,然后在响应中出现以下内容:
{ [Error: connect ECONNREFUSED 127.0.0.1:3000] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 3000 }
我试过在服务器代码中放入不同的callback函数,但是没有任何区别。 我想我应该扼杀对服务器的请求,但我不知道如何实现这一点。
任何帮助将不胜感激。
大多数系统的ulimit默认值是1024.请参阅limits.conf手册( http://linux.die.net/man/5/limits.conf )。
虽然@ migg是正确的,确保您的应用程序没有内存泄漏,其过程处理调整系统的高负载也是不less应用程序的正常程序。
试试看看是否有帮助;
$ ulimit -n 65535
编辑:我没有testing过,但这里是关于Windows的ibm文件; http://www-01.ibm.com/support/docview.wss?uid=swg21392080