mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00

Some cases use both `cluster` and `net`/`cluser` will throw ERR_INTERNAL_ASSERTION when `listen`/`bind` to the port of `0`. This PR maitains a separate map of the index to fix the issue. See the new tests added for the detail cases. PR-URL: https://github.com/nodejs/node/pull/36764 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
32 lines
784 B
JavaScript
32 lines
784 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const Countdown = require('../common/countdown');
|
|
const cluster = require('cluster');
|
|
const net = require('net');
|
|
|
|
// Test an edge case when using `cluster` and `net.Server.listen()` to
|
|
// the port of `0`.
|
|
const kPort = 0;
|
|
|
|
function child() {
|
|
const kTime = 2;
|
|
const countdown = new Countdown(kTime * 2, () => {
|
|
process.exit(0);
|
|
});
|
|
for (let i = 0; i < kTime; i += 1) {
|
|
const server = net.createServer();
|
|
server.listen(kPort, common.mustCall(() => {
|
|
server.close(countdown.dec());
|
|
const server2 = net.createServer();
|
|
server2.listen(kPort, common.mustCall(() => {
|
|
server2.close(countdown.dec());
|
|
}));
|
|
}));
|
|
}
|
|
}
|
|
|
|
if (cluster.isMaster)
|
|
cluster.fork(__filename);
|
|
else
|
|
child();
|