NodeJS Cluster unexpected assert.AssertionError

∥☆過路亽.° 提交于 2019-12-04 06:39:05

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.

Had same problem - this is now working:

cluster.on('disconnect', function(worker) {
  if (this.isMaster) {
    console.log('worker ' + worker.process.pid + ' disconnected');
    cluster.fork();
  }
});

as referenced by @OrangeDog.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!