nodejs cluster module - 正在使用的地址错误 [英] nodejs cluster module - Address in use error

查看:91
本文介绍了nodejs cluster module - 正在使用的地址错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an express.js application and it has to run a sub-process everytime there is a particular request (here it is : /compute/real-time ). There will be user-created scripts to compute the data. So, I am using node cluster module to create a pool of workers and pick the one which is free to execute the scripts. But I have hit the wall during the creation of cluster itself. Here is the code 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

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)

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

IS there any way out for this problem please? Thanks in advance

推荐答案

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

This is one of the cases, when your server code faces an error and due to improper error handling, we get exception but the port is still busy. So you need to clear out the application which has reserved that port. If you are using linux, you can use

lsof -i :3000

获取进程ID并使用

kill -9 #processId

然后重新启动服务器。

这篇关于nodejs cluster module - 正在使用的地址错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆