【问题标题】:nodejs cluster module - Address in use errornodejs集群模块 - 使用中的地址错误
【发布时间】:2014-02-25 23:31:04
【问题描述】:

我有一个 express.js 应用程序,每次有特定请求时它都必须运行一个子进程(这里是:/compute/real-time)。将有用户创建的脚本来计算数据。所以,我正在使用节点集群模块来创建一个工作人员池,并选择一个可以免费执行脚本的工作人员。但是我在创建集群本身的过程中遇到了困难。这是代码 clusterPool.js

var cluster = require('cluster');
exports.setupCluster = function(){
console.log ("Setting up cluster for bot processing " )
  if (cluster.isMaster){
    cluster.fork();   //one is good enough at the moment
  }
}

计算.js

var async = require('async');
var clusterPool = require('.././clusterPool')
//Start the cluster
clusterPool.setupCluster();
exports.computeRealTime = function(req,res){
    clusterPool.cluster.on("listening",function(worker){
        //....Do something with the worker
    })
}

webserver.js

// Include Express
var express = require('express');
var compute = require('.././compute');

// Create a new Express application
var app = express();

// Add a basic route – index page
app.get('/compute/real-time',compute.computeRealTime);

// Bind to a port
app.listen(3000);

这是我面临的错误:

error:  code=EADDRINUSE, errno=EADDRINUSE, syscall=bind
error: Error: bind EADDRINUSE
at errnoException (net.js:884:11)
at net.js:1056:26
at Object.1:2 (cluster.js:587:5)
at handleResponse (cluster.js:171:41)
at respond (cluster.js:192:5)
at handleMessage (cluster.js:202:5)
at process.EventEmitter.emit (events.js:117:20)
at handleMessage (child_process.js:318:10)
at child_process.js:392:7
at process.handleConversion.net.Native.got (child_process.js:91:7)

请问有什么办法可以解决这个问题吗? 提前致谢

【问题讨论】:

    标签: javascript node.js express cluster-computing


    【解决方案1】:

    这是其中一种情况,当您的服务器代码遇到错误并且由于错误处理不当而导致异常但端口仍然繁忙时。因此,您需要清除保留该端口的应用程序。如果你使用的是 linux,你可以使用

    lsof -i :3000
    

    获取进程ID并使用终止该进程

    kill -9 #processId
    

    然后重启你的服务器。

    【讨论】:

    • 感谢@blunderboy 的评论。但是,这里的同一个快速应用程序正在使用端口 3000。我正在尝试在同一应用程序中运行内部集群以进行不同的请求处理
    • 你能给我一些建议吗?我也在尝试做同样的事情,但谷歌现在似乎不是好朋友!
    猜你喜欢
    • 2014-06-01
    • 2020-06-23
    • 2015-04-03
    • 1970-01-01
    • 2019-07-21
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多