1'use strict'; 2const common = require('../common'); 3const Countdown = require('../common/countdown'); 4if (common.isWindows) 5 common.skip('dgram clustering is currently not supported on Windows.'); 6 7const cluster = require('cluster'); 8const dgram = require('dgram'); 9 10// Test an edge case when using `cluster` and `dgram.Socket.bind()` 11// the port of `0`. 12const kPort = 0; 13 14function child() { 15 const kTime = 2; 16 const countdown = new Countdown(kTime * 2, () => { 17 process.exit(0); 18 }); 19 for (let i = 0; i < kTime; i += 1) { 20 const socket = new dgram.Socket('udp4'); 21 socket.bind(kPort, common.mustCall(() => { 22 // `process.nextTick()` or `socket2.close()` would throw 23 // ERR_SOCKET_DGRAM_NOT_RUNNING 24 process.nextTick(() => { 25 socket.close(countdown.dec()); 26 const socket2 = new dgram.Socket('udp4'); 27 socket2.bind(kPort, common.mustCall(() => { 28 process.nextTick(() => { 29 socket2.close(countdown.dec()); 30 }); 31 })); 32 }); 33 })); 34 } 35} 36 37if (cluster.isMaster) 38 cluster.fork(__filename); 39else 40 child(); 41