gnode
gnode copied to clipboard
cluster.isMaster returns true for forked processes
The canonical node cluster example doesn't function correctly when invoked using gnode.
// Server code
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
console.log("Forking process")
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
// Workers can share any TCP connection
// In this case its a HTTP server
http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
console.log("Created server")
}
When invoked with gnode (using node 0.10.28), cluster.isMaster returns true for every process, resulting in an infinite forking routine. Invoking the file with node gives the expected results, as do both gnode and node with node 0.11.*.
I am also encountering this issue
A fix is available at PR #22.