on node v0.12.0
Show my simple test module using cluster
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat use_cluster.js
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
function CallCluster(cb) {
this.server = http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
});
}
CallCluster.prototype.listen = function(port, cb) {
console.log("running...");
if (cluster.isMaster) {
cluster.fork();
cluster.on('listening', function(){console.log("listening...")});
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
this.server.listen(port);
setImmediate(cb.bind(http));
}
};
module.exports = CallCluster;
A simple script to call the module
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat call_call_cluster.js
var CallCluster = require("./use_cluster.js");
var cc = new CallCluster();
cc.listen(9999, function(){console.log("listening")});
Running that file, everything works, the listen() calls its callback and the script keeps running.
(master) [fcorrea@dev04c6 ~/olx_push_service]$ node call_call_cluster.js
running...
running...
listening
listening...
^C
Running the same script by "node -e" does't call the listen() callback, the worker dies and the script stops running
(master) [fcorrea@dev04c6 ~/olx_push_service]$ node -e '
var CallCluster = require("./use_cluster.js");
var cc = new CallCluster();
cc.listen(9999, function(){console.log("listening")});
'
running...
running...
listening
worker 16384 died
(master) [fcorrea@dev04c6 ~/olx_push_service]$
Is that a bug? Why isn't that working?
on node v0.12.0
Show my simple test module using cluster
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat use_cluster.jsA simple script to call the module
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat call_call_cluster.jsRunning that file, everything works, the listen() calls its callback and the script keeps running.
(master) [fcorrea@dev04c6 ~/olx_push_service]$ node call_call_cluster.js running... running... listening listening... ^CRunning the same script by "node -e" does't call the listen() callback, the worker dies and the script stops running
Is that a bug? Why isn't that working?