简体   繁体   English

每次运行cluster.fork()时,都会出现错误:绑定EADDRINUSE

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

I'm using node.js, and using the cluster module. 我正在使用node.js,并使用集群模块。 Everytime I run cluster.fork(), I always get a 每次我运行cluster.fork(),我总是得到一个

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 这是在我通过调用节点app.js运行的app.js中调用的函数

我使用所有线程不止一次启动服务器,因此端口已被绑定

The stack trace you provide indicates that EADDRINUSE is coming from the net module. 您提供的堆栈跟踪表明EADDRINUSE来自net模块。 EADDRINUSE typically means that you are trying to listen on an IP/port combination more than once. EADDRINUSE通常意味着您尝试EADDRINUSE侦听IP /端口组合。 So, for example, if this is a clustered web server, perhaps all your workers are trying to bind to port 80 on the same IP address. 因此,例如,如果这是一个集群Web服务器,也许所有工作者都试图绑定到同一IP地址上的端口80。 Without more code, it's impossible to tell what's happening. 没有更多的代码,就无法分辨出发生了什么。

The example code you gave in the subsequent comment does not trigger EADDRINUSE for me. 您在后续注释中提供的示例代码不会为我触发EADDRINUSE Instead it errors with cluster.fork is not a function because there's no check for cluster.isMaster before calling cluster.fork() . 相反, cluster.fork is not a function错误cluster.fork is not a function因为在调用cluster.fork()之前没有检查cluster.isMaster

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM