You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
738 B

'use strict';
const common = require('../common');
const http = require('http');
const cluster = require('cluster');
const assert = require('assert');
cluster.schedulingPolicy = cluster.SCHED_NONE;
const server = http.createServer();
if (cluster.isMaster) {
let worker;
server.listen(0, common.mustCall((error) => {
assert.ifError(error);
assert(worker);
worker.send({port: server.address().port});
}));
worker = cluster.fork();
worker.on('exit', common.mustCall(() => {
server.close();
}));
} else {
process.on('message', common.mustCall((msg) => {
assert(msg.port);
server.listen(msg.port);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
}));
}));
}