NodeJS Cluster意外断言.AssertionError [英] NodeJS Cluster unexpected assert.AssertionError

查看:233
本文介绍了NodeJS Cluster意外断言.AssertionError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个奇怪的错误,这是我的主要.js文件

I am facing an weird error, this is my main .js file

var cluster = require('cluster'),
  express = require('express'),
  http = require('http');

if (cluster.isMaster) {
    var cpuCount = require('os').cpus().length;
    for (var i = 0; i < cpuCount; i += 1) {
      cluster.fork();
    }
} else {
  var app = express(),
  server = http.createServer(app),
  io = require('socket.io').listen(server);
  io.set('log level', 2);
  server.listen(3000);
}

cluster.on('exit', function (worker) {
    console.log('Worker ' + worker.id + ' died :(');
    cluster.fork();
});

这是错误讯息我得到..

This is the error message i am getting..

Worker 1 died :(
Worker 2 died :(

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: false == true
    at Cluster.cluster.fork (cluster.js:500:3)
    at Cluster.<anonymous> (/xxx/x/xxx/xxx/xxxxx.js:21:13)
    at Cluster.EventEmitter.emit (events.js:106:17)
    at process.<anonymous> (cluster.js:341:13)
    at process.g (events.js:180:16)
    at process.EventEmitter.emit (events.js:95:17)
    at process.exit (node.js:707:17)
    at process.<anonymous> (cluster.js:545:15)
    at process.g (events.js:180:16)
    at process.EventEmitter.emit (events.js:117:20)

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: false == true
    at Cluster.cluster.fork (cluster.js:500:3)
    at Cluster.<anonymous> (/xxx/x/xxx/xxx/xxxxx.js:21:13)
    at Cluster.EventEmitter.emit (events.js:106:17)
    at process.<anonymous> (cluster.js:341:13)
    at process.g (events.js:180:16)
    at process.EventEmitter.emit (events.js:95:17)
    at process.exit (node.js:707:17)
    at process.<anonymous> (cluster.js:545:15)
    at process.g (events.js:180:16)
    at process.EventEmitter.emit (events.js:117:20)

不知道有什么问题吗?

No idea whats wrong there any help ?

硬件概述:

  Model Name:   MacBook
  Model Identifier: MacBook5,2
  Processor Name:   Intel Core 2 Duo
  Processor Speed:  2.13 GHz
  Number of Processors: 1
  Total Number of Cores:    2
  L2 Cache: 3 MB
  Memory:   2 GB
  Bus Speed:    1.07 GHz
  Boot ROM Version: MB52.0088.B05
  SMC Version (system): 1.38f5
  Sudden Motion Sensor:
  State:    Enabled

系统版本:OS X 10.9.1(13B42 )

System Version: OS X 10.9.1 (13B42)

内核版本:达尔文13.0.0

Kernel Version: Darwin 13.0.0

$ uname -a
Darwin Nikhils-MacBook.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
$ node --version
v0.10.24
$ npm --version
1.3.21


推荐答案

cluster.js第500行

cluster.js line 500 is

assert(cluster.isMaster);

即。你从另一个工人(或Node认为你)那里调用 fork

i.e. you're calling fork from another worker (or Node thinks you are).

如果移动 cluster.on('exit'监听器进入 if(cluster.isWorker)块无法解决问题,那么我想你应该在Github上打开 的问题,因为我无法理解为什么会在任何事件中发出该事件工人。

If moving the cluster.on('exit' listener into the if (cluster.isWorker) block does not resolve the issue, then I think you should open an issue on Github, as I can't see why the event would be emitted in any workers.

编辑:它确实是一个错误

这篇关于NodeJS Cluster意外断言.AssertionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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