Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Everytime I run cluster.fork(), I get a Error: bind EADDRINUSE

I'm using node.js, and using the cluster module. Everytime I run cluster.fork(), I always get a

throw er; // Unhandled 'error' event
Error: bind EADDRINUSE
    at exports._errnoException (util.js:746:11)
at cb (net.js:1205:33)
at rr (cluster.js:592:14)
at Worker.<anonymous> (cluster.js:563:9)
at process.<anonymous> (cluster.js:692:8)
at process.emit (events.js:129:20)
at handleMessage (child_process.js:324:10)
at Pipe.channel.onread (child_process.js:352:11)

I've been googling this, and I have no idea how this is happening because I'm not passing in any port numbers.

Thanks

EDIT: Posting code

var setupWorkers = function() {
   if (cluster.isMaster) {
   // Fork workers.
       for (var i = 0; i < 5; i++) {
       cluster.fork();
   }

 }

and this is a function that is called in the app.js which I run by calling node app.js

like image 618
Gakho Avatar asked Sep 12 '15 00:09

Gakho


1 Answers

I was starting a server more than once with all the threads so the port was bound already

like image 182
Gakho Avatar answered Oct 02 '22 04:10

Gakho