我面临一个奇怪的错误,这是我的主要.js文件
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();
});
这是我收到的错误消息..
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)
不知道有什么帮助吗?
硬件概述:
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)
内核版本: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
答案 0 :(得分:4)
assert(cluster.isMaster);
即。你正在从另一个工人(或Node认为你)调用fork
。
如果将cluster.on('exit'
监听器移到if (cluster.isWorker)
区块无法解决问题,那么我认为您应该打开问题on Github,因为我无法理解为什么会发生此事件在任何工人中被释放。
答案 1 :(得分:0)
有同样的问题 - 现在正在运作:
cluster.on('disconnect', function(worker) {
if (this.isMaster) {
console.log('worker ' + worker.process.pid + ' disconnected');
cluster.fork();
}
});
由@OrangeDog引用的。