2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2012-01-18 00:10:22 +01:00
|
|
|
// Installing a custom uncaughtException handler should override the default
|
|
|
|
// one that the cluster module installs.
|
|
|
|
// https://github.com/joyent/node/issues/2556
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-10-20 23:32:34 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const cluster = require('cluster');
|
|
|
|
const fork = require('child_process').fork;
|
2012-01-18 00:10:22 +01:00
|
|
|
|
2016-10-20 23:32:34 -05:00
|
|
|
const MAGIC_EXIT_CODE = 42;
|
2012-01-18 00:10:22 +01:00
|
|
|
|
2016-10-20 23:32:34 -05:00
|
|
|
const isTestRunner = process.argv[2] !== 'child';
|
2012-01-18 00:10:22 +01:00
|
|
|
|
|
|
|
if (isTestRunner) {
|
2016-10-20 23:32:34 -05:00
|
|
|
const master = fork(__filename, ['child']);
|
|
|
|
master.on('exit', common.mustCall((code) => {
|
2016-07-15 15:43:24 -04:00
|
|
|
assert.strictEqual(code, MAGIC_EXIT_CODE);
|
|
|
|
}));
|
2016-07-08 17:17:47 -07:00
|
|
|
} else if (cluster.isMaster) {
|
2016-10-20 23:32:34 -05:00
|
|
|
process.on('uncaughtException', common.mustCall(() => {
|
|
|
|
process.nextTick(() => process.exit(MAGIC_EXIT_CODE));
|
|
|
|
}));
|
2012-01-18 00:10:22 +01:00
|
|
|
cluster.fork();
|
|
|
|
throw new Error('kill master');
|
2016-07-08 17:17:47 -07:00
|
|
|
} else { // worker
|
2012-01-18 00:10:22 +01:00
|
|
|
process.exit();
|
|
|
|
}
|