mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
2c1b9f506a
RefsL https://github.com/nodejs/node/pull/45027 PR-URL: https://github.com/nodejs/node/pull/45047 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
27 lines
690 B
JavaScript
27 lines
690 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.isPrimary) {
|
|
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());
|
|
server.listen(process.env.PORT);
|
|
server.on('error', common.mustCall((e) => {
|
|
cluster.worker.disconnect();
|
|
throw e;
|
|
}));
|
|
}
|