mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
8e3f606779
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>
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const Countdown = require('../common/countdown');
|
|
if (common.isWindows)
|
|
common.skip('dgram clustering is currently not supported on Windows.');
|
|
|
|
const cluster = require('cluster');
|
|
const dgram = require('dgram');
|
|
|
|
// Test an edge case when using `cluster` and `dgram.Socket.bind()`
|
|
// 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 socket = new dgram.Socket('udp4');
|
|
socket.bind(kPort, common.mustCall(() => {
|
|
// `process.nextTick()` or `socket2.close()` would throw
|
|
// ERR_SOCKET_DGRAM_NOT_RUNNING
|
|
process.nextTick(() => {
|
|
socket.close(countdown.dec());
|
|
const socket2 = new dgram.Socket('udp4');
|
|
socket2.bind(kPort, common.mustCall(() => {
|
|
process.nextTick(() => {
|
|
socket2.close(countdown.dec());
|
|
});
|
|
}));
|
|
});
|
|
}));
|
|
}
|
|
}
|
|
|
|
if (cluster.isMaster)
|
|
cluster.fork(__filename);
|
|
else
|
|
child();
|