Skip to content

Server.getConnections() failed with "Slave closed before reply" #13923

Closed
@kavinwang

Description

@kavinwang

node version : 4.x - 6.x
os: macos linux

save the following codes to a file like 'server.js', and run node server.js
then run this test code in another console:

for i in {1..1500}; do curl http://localhost:12345; sleep 1; echo "---- $i\n"; done

server.js :

'use strict';
var cluster = require('cluster');
var net = require('net');
if (cluster.isMaster) {
    console.log('Nodejs version :', process.version);
    var cpuCount = require('os').cpus().length;
    var workers = [];

    var spawn = function(workerIndex) {
        var worker = cluster.fork();
        workers[workerIndex] = worker;
        worker.on('exit', function() {
            spawn(workerIndex);
        });
    };
    for (var i = 0; i < cpuCount; i++) spawn(i);

    var masterHttpServer = net.createServer({ pauseOnConnect: true }, function(socket) {
        //var worker = workers[Number('0' + socket.remoteAddress.replace(/[abcdef:.]/g, '')) % cpuCount];
        var worker = workers[0];
        worker.send('xxx-http-session:connection', socket);
    }).listen(12345);

    setInterval(function() {
        //XXX: will return errors if some worker dies with unclosed socket
        masterHttpServer.getConnections(function(err, counts) {
            if (!err) console.info('active connections : ' + counts);
            else console.info('errors ocurred when getConnections :' + err);
        });
    }, 1000);

    setInterval(function() {
       workers[0].kill();
    }, 1000);

} else {
    var server = require('http').createServer(function(req, res) {
        res.end('Anythings returns to the browser! ');
    });

    process.on('message', function(message, socket) {
        if (message !== 'xxx-http-session:connection') return;
        server.emit('connection', socket);
        socket.resume();
    });
}

process.on('uncaughtException', function(err) {
    console.log('uncaughtException:', err.stack);
});
process.on('exit', function(code) {
    console.warn('process is down ! exit code :', code);
});

Server.getConnections() will fail with "Slave closed before reply"; and will nerver come back !

output:

Nodejs version : v6.11.0
active connections : 0
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply
errors ocurred when getConnections :Error: Slave closed before reply

I think that is a bug !
thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    clusterIssues and PRs related to the cluster subsystem.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions