Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Cluster unexpected assert.AssertionError

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 ?

Hardware Overview:

  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

System Version: OS X 10.9.1 (13B42)

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
like image 843
niksmac Avatar asked Jan 19 '14 13:01

niksmac


1 Answers

cluster.js line 500 is

assert(cluster.isMaster);

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

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.

Edit: It was indeed a bug.

like image 165
OrangeDog Avatar answered Sep 28 '22 07:09

OrangeDog