Every time I run cluster.fork (), I get an error: bind EADDRINUSE

I am using node.js and using the cluster module. Every time I run cluster.fork (), I always get

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 was looking for this, and I have no idea how this happens because I am not transmitting the port numbers.

thanks

EDIT: Code Posting

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

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

+6
source share
2 answers

I started the server several times with all threads, so the port was already connected

0
source

The stack trace indicates that EADDRINUSE comes from the net module. EADDRINUSE usually means that you are trying to listen to the IP / port combination more than once. So, for example, if it is a clustered web server, it is possible that all your employees are trying to associate port 80 with the same IP address. Without additional code, it is impossible to say what is happening.

The sample code that you provided in the following comment does not call EADDRINUSE for me. Instead, these are errors with cluster.fork is not a function , because there is no check on cluster.isMaster before calling cluster.fork() .

0
source

All Articles