gnode icon indicating copy to clipboard operation
gnode copied to clipboard

cluster.isMaster returns true for forked processes

Open oortlieb opened this issue 11 years ago • 2 comments

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.*.

oortlieb avatar Jun 13 '14 18:06 oortlieb

I am also encountering this issue

blowsie avatar May 06 '15 09:05 blowsie

A fix is available at PR #22.

etiktin avatar May 27 '15 22:05 etiktin