mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 00:19:41 +00:00

PR-URL: https://github.com/nodejs/node/pull/14162 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
34 lines
740 B
JavaScript
34 lines
740 B
JavaScript
'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();
|
|
}));
|
|
}));
|
|
}
|