{"action":"opened","issue":{"url":"https://api.github.com/repos/joyent/node/issues/14168","labels_url":"https://api.github.com/repos/joyent/node/issues/14168/labels{/name}","comments_url":"https://api.github.com/repos/joyent/node/issues/14168/comments","events_url":"https://api.github.com/repos/joyent/node/issues/14168/events","html_url":"https://github.com/joyent/node/issues/14168","id":64601418,"number":14168,"title":"listen() dosen't work with cluster on \"node -e\"","user":{"login":"FCO","id":99834,"avatar_url":"https://avatars.githubusercontent.com/u/99834?v=3","gravatar_id":"","url":"https://api.github.com/users/FCO","html_url":"https://github.com/FCO","followers_url":"https://api.github.com/users/FCO/followers","following_url":"https://api.github.com/users/FCO/following{/other_user}","gists_url":"https://api.github.com/users/FCO/gists{/gist_id}","starred_url":"https://api.github.com/users/FCO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FCO/subscriptions","organizations_url":"https://api.github.com/users/FCO/orgs","repos_url":"https://api.github.com/users/FCO/repos","events_url":"https://api.github.com/users/FCO/events{/privacy}","received_events_url":"https://api.github.com/users/FCO/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-26T18:28:46Z","updated_at":"2015-03-26T18:28:46Z","closed_at":null,"body":"on node v0.12.0\r\n\r\nShow my simple test module using **cluster**\r\n\r\n```bash\r\n(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat use_cluster.js \r\n```\r\n\r\n```javascript\r\nvar cluster = require('cluster');\r\nvar http = require('http');\r\nvar numCPUs = require('os').cpus().length;\r\n\r\nfunction CallCluster(cb) {\r\n\tthis.server = http.createServer(function(req, res) {\r\n\t\tres.writeHead(200);\r\n\t\tres.end(\"hello world\\n\");\r\n\t});\r\n}\r\nCallCluster.prototype.listen = function(port, cb) {\r\n\tconsole.log(\"running...\");\r\n\tif (cluster.isMaster) {\r\n\t\tcluster.fork();\r\n\t\tcluster.on('listening', function(){console.log(\"listening...\")});\r\n\t\tcluster.on('exit', function(worker, code, signal) {\r\n\t\t\tconsole.log('worker ' + worker.process.pid + ' died');\r\n\t\t});\r\n\t} else {\r\n\t\tthis.server.listen(port);\r\n\t\tsetImmediate(cb.bind(http));\r\n\t}\r\n};\r\n\r\nmodule.exports = CallCluster;\r\n```\r\n\r\nA simple script to call the module\r\n\r\n```bash\r\n(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat call_call_cluster.js \r\n```\r\n```javascript\r\nvar CallCluster = require(\"./use_cluster.js\");\r\n\r\nvar cc = new CallCluster();\r\n\r\ncc.listen(9999, function(){console.log(\"listening\")});\r\n```\r\n\r\nRunning that file, everything works, the listen() calls its callback and the script keeps running.\r\n\r\n```bash\r\n(master) [fcorrea@dev04c6 ~/olx_push_service]$ node call_call_cluster.js \r\nrunning...\r\nrunning...\r\nlistening\r\nlistening...\r\n^C\r\n```\r\n\r\nRunning the same script by \"node -e\" does't call the listen() callback, the worker dies and the script stops running\r\n```bash\r\n(master) [fcorrea@dev04c6 ~/olx_push_service]$ node -e '                       \r\nvar CallCluster = require(\"./use_cluster.js\");\r\n\r\nvar cc = new CallCluster();\r\n\r\ncc.listen(9999, function(){console.log(\"listening\")});\r\n\r\n'\r\nrunning...\r\nrunning...\r\nlistening\r\nworker 16384 died\r\n(master) [fcorrea@dev04c6 ~/olx_push_service]$\r\n```\r\n\r\nIs that a bug? Why isn't that working?"}}