• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const http = require('http');
4const cluster = require('cluster');
5const assert = require('assert');
6
7cluster.schedulingPolicy = cluster.SCHED_RR;
8
9const server = http.createServer();
10
11if (cluster.isPrimary) {
12  server.listen({ port: 0 }, common.mustCall(() => {
13    const worker = cluster.fork({ PORT: server.address().port });
14    worker.on('exit', common.mustCall(() => {
15      server.close();
16    }));
17  }));
18} else {
19  assert(process.env.PORT);
20  process.on('uncaughtException', common.mustCall());
21  server.listen(process.env.PORT);
22  server.on('error', common.mustCall((e) => {
23    cluster.worker.disconnect();
24    throw e;
25  }));
26}
27