nodejs longpoll socket挂断错误

时间:2015-06-25 11:07:09

标签: node.js sockets long-polling

我有一个小应用程序(在Node.JS中),通过https.request将一堆longpolling连接连接到服务器

 var data = "{'foo':'bar'}";  
 var options = {
        'host'               : '127.0.0.1',
        'port'               : '443',
        'path'               : '/push',
        'method'             : 'POST',
        'rejectUnauthorized' : false,
        'agent'              : false,
        'headers'            : {
            'Content-Type': 'application/json',
            'Content-Length': data.length
        }
    };
       var request = require('https').request(options, function(responseStream){

            responseStream.setEncoding('utf8');

            var responseData = "";
            responseStream.on('data', function (chunk) {
                responseData += chunk;
            });

            responseStream.on('end', function() {

                // trigger callback on master
                process.send({
                    "type"     : Constants.PROCESSORS.MESSAGE.REPLY,
                    "data"     : responseData
                });

            });

        });

        request.write(data);
        request.end();

请求inits,接收套接字,大约20秒后我收到套接字挂起错误。它永远不会到达连接的'州('连接'事件未被抛出)。

错误callstack:

"Error: socket hang up
at createHangUpError (_http_client.js:192:15)
at TLSSocket.socketOnEnd (_http_client.js:270:23)
at emitNone (events.js:70:20)
at TLSSocket.emit (events.js:147:7)
at _stream_readable.js:891:16
at process._tickCallback (node.js:337:11)"

修改 我忘了提到远程服务器是使用HAProxy的平衡器,但我设法用一个简单的服务器(没有平衡器,只是node.js web服务器)重现它

0 个答案:

没有答案