2016-02-01 65 views
2

我的节点/回送服务器有一个零星的问题。我的设置如下:Node.js零星的'ECONNREFUSED'错误request.get

编辑:我的节点版本是v4.2.4,我在Windows 10 Professional上运行节点。

客户端:

  • 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

    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 } 

我已经试过投入的不同回调服务器代码,但没有任何区别。我想我应该扼杀对服务器的请求,但我不知道如何实现这一点。

任何帮助将不胜感激。

+0

您正在运行哪个版本的节点? – migg

+0

@migg我正在运行v4.2.4 – Oddball

+0

嗯......你的参数被称为'callback',但你正在调用'cb'。也许你正在创建一个memleak,直到服务器拒绝连接? – migg

回答

1

大多数系统的ulimit默认值为1024.请参阅limits.conf手册(http://linux.die.net/man/5/limits.conf)。

虽然@ migg关于确保您的应用程序中没有内存泄漏并且它的流程处理是正确的,但调整系统的高负载也是很多应用程序的正常流程。

试试看看是否有帮助;

$的ulimit -n 65535

编辑:我没有测试过这一点,但这里是IBM关于Windows中的文件; http://www-01.ibm.com/support/docview.wss?uid=swg21392080

+0

我应该提到我正在开发Windows 10机器。我不确定你是否可以在Windows中设置ulimit。 – Oddball

+0

更新了答案 –

+0

感谢您的建议。看来微软的基于UNIX的应用程序子系统(SUA)或Windows服务UNIX版(SFU)在Windows 8.1 Enterprise中都被弃用,所以我不能修改这些注册表值,因为它们在Windows 10上不存在。 – Oddball