blob: d19cf0c3811aa5cc623c4215993b34e36c331491 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
'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;
}));
}
|