Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kavinwang opened this issue Jun 26, 2017 · 2 comments
Closed

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

kavinwang opened this issue Jun 26, 2017 · 2 comments
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem.

Comments

@kavinwang
Copy link

kavinwang commented Jun 26, 2017

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!

@mscdex mscdex added net Issues and PRs related to the net subsystem. cluster Issues and PRs related to the cluster subsystem. labels Jun 26, 2017
@XadillaX
Copy link
Contributor

Can you minify your code to reproduce this problem?

@apapirovski
Copy link
Member

Given the lack of a follow up and no one taking this up, I'm going to go ahead and close. If anyone happens to have any additional information or believes this should remain open, please feel free to do so. Just cleaning up the issue tracker a tad...

This was referenced Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants