-
Notifications
You must be signed in to change notification settings - Fork 7.3k
listen() dosen't work with cluster on "node -e" #14168
Comments
Thank you for reporting this issue! It's a bug in the sense that using I don't know if that's intentional. I don't see any strong reason why one couldn't use the cluster module with The sample code you used to reproduce the problem has another issue: it basically executes This bug can be reproduced with the example provided in the cluster's API documentation. Thank you again! |
I had another problem with the "-e" flag: calling the code by a file, the listen()'s callback is called "immediately" (master) [fcorrea@dev04c6 ~/olx_rest]$ cat test2-e.js require("http").createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(9999, function(){console.log("bla")}); (master) [fcorrea@dev04c6 ~/olx_rest]$ node test2-e.js
bla
^C When I run the same code with "node -e" the callback waits until the first http request to run (master) [fcorrea@dev04c6 ~/olx_rest]$ node -e '
require("http").createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(9999, function(){console.log("bla")});
'
^C
(master) [fcorrea@dev04c6 ~/olx_rest]$
(master) [fcorrea@dev04c6 ~/olx_rest]$ node -e '
require("http").createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(9999, function(){console.log("bla")});
' &
[1] 27557
(master) [fcorrea@dev04c6 ~/olx_rest]$ curl 127.0.0.1:9999
bla
hello world
(master) [fcorrea@dev04c6 ~/olx_rest]$ |
I don't really see a use case for using the EDIT: By not ideal use case, I was referring to the EDIT2: If you have your heart set on using this approach, this hack appears to work. Add the following two lines immediately before your call to cluster.settings.exec = __filename;
cluster.settings.execArgv = []; |
You can't call cluster.fork() from the node REPL, either. Use |
on node v0.12.0
Show my simple test module using cluster
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat use_cluster.js
A simple script to call the module
(master) [fcorrea@dev04c6 ~/olx_push_service]$ cat call_call_cluster.js
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
Is that a bug? Why isn't that working?
The text was updated successfully, but these errors were encountered: