node.js - 每次运行 cluster.fork() 时,我都会收到错误 : bind EADDRINUSE

标签 node.js master-slave

我正在使用 node.js,并使用集群模块。每次我运行 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)

我一直在用谷歌搜索这个,但我不知道这是怎么回事,因为我没有传递任何端口号。

谢谢

编辑:发布代码

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

 }

这是在我通过调用 node app.js 运行的 app.js 中调用的函数

最佳答案

我用所有线程多次启动服务器,所以端口已经绑定(bind)

关于node.js - 每次运行 cluster.fork() 时,我都会收到错误 : bind EADDRINUSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32533924/

相关文章:

node.js - 更改 Jade 中的字体和颜色

node.js - sequelize 中 findOrCreate() 和 upsert() 的区别

javascript - Node 和 MySQL - 解决 "Too Many Connections"问题

kubernetes - 将 redis-sentinel 连接到 Kubernetes 上的 redis-master

Mysql slave 重启后崩溃

mongodb - mongodb slave 上的数据库与 master 不相同

javascript - 通过 for 循环内的异步函数设置变量

javascript - 如何将变量从 Node JS 传递到前端 JS

nosql - 可靠性:主/从模式是注定的吗?

mysql - tungsten 从 mysql slave 复制到 vertica - 似乎没有查看中继日志?