mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 17:32:22 +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>
27 lines
698 B
JavaScript
27 lines
698 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const cluster = require('cluster');
|
|
const assert = require('assert');
|
|
|
|
cluster.schedulingPolicy = cluster.SCHED_RR;
|
|
|
|
const server = http.createServer();
|
|
|
|
if (cluster.isMaster) {
|
|
server.listen({ port: 0 }, common.mustCall(() => {
|
|
const worker = cluster.fork({ PORT: server.address().port });
|
|
worker.on('exit', common.mustCall(() => {
|
|
server.close();
|
|
}));
|
|
}));
|
|
} else {
|
|
assert(process.env.PORT);
|
|
process.on('uncaughtException', common.mustCall((e) => {}));
|
|
server.listen(process.env.PORT);
|
|
server.on('error', common.mustCall((e) => {
|
|
cluster.worker.disconnect();
|
|
throw e;
|
|
}));
|
|
}
|