node.js:集群主进程中的异常:通道已关闭

时间:2012-03-15 07:17:59

标签: node.js socket.io cluster-computing

我的node.js集群能够启动2个工作进程并且工作正常。 这是伪代码。 但是,如果我打开Windows任务管理器来杀死node.js进程,我预计它会重新启动。但它引发了错误(错误:频道关闭)。

if (cluster.isMaster) {

  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('death', function(worker) {
    logger.fatal('worker ' + worker.pid + ' died. Restarting again ...');

    cluster.fork();


  });

} else {
  // Worker processes have a express server.
  .........
  .........
}

错误:

[2012-03-15 09:46:20.906] [INFO] console - Total CPUs :  2
[2012-03-15 09:46:22.182] [INFO] console -    info  - 'socket.io started'
[2012-03-15 09:46:22.240] [INFO] console -    info  - 'socket.io started'
[2012-03-15 12:20:04.973] [FATAL] choicebeat - worker 6928 died. Restarting agai
n ...
[2012-03-15 12:20:05.213] [ERROR] console - Exception in cluster master process:
 channel closed
Error: channel closed
    at ChildProcess.send (child_process.js:118:33)
    at c:\HTML5\LIKEPREF\test\server\node_modules\socket.io-clusterhub\node_modu
les\clusterhub\lib\index.js:150:22
    at Array.forEach (native)
    at ChildProcess.onmessage (c:\HTML5\LIKEPREF\test\server\node_modules\socket
.io-clusterhub\node_modules\clusterhub\lib\index.js:149:15)
    at ChildProcess.emit (events.js:88:20)
    at Pipe.onread (child_process.js:102:16)

看起来socket.io-clusterhub有问题。这是某种配置错误还是错误?

1 个答案:

答案 0 :(得分:0)

该问题已在最新的clusterhub版本0.1.2中得到解决 socket.io-clusterhub在内部使用clusterhub,所以如果你更新socket.io-clusterhub,它应该可以工作。

参考:https://github.com/fent/socket.io-clusterhub/issues/1#issuecomment-4538131