mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

This fixes closing dgram sockets right after binding in cluster workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors. PR-URL: https://github.com/nodejs/node/pull/43709 Fixes: https://github.com/nodejs/node/issues/40671 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
30 lines
688 B
JavaScript
30 lines
688 B
JavaScript
'use strict';
|
|
// Ensure that closing dgram sockets in 'listening' callbacks of cluster workers
|
|
// won't throw errors.
|
|
|
|
const common = require('../common');
|
|
const dgram = require('dgram');
|
|
const cluster = require('cluster');
|
|
if (common.isWindows)
|
|
common.skip('dgram clustering is currently not supported on windows.');
|
|
|
|
if (cluster.isPrimary) {
|
|
for (let i = 0; i < 3; i += 1) {
|
|
cluster.fork();
|
|
}
|
|
} else {
|
|
const socket = dgram.createSocket('udp4');
|
|
|
|
socket.on('error', common.mustNotCall());
|
|
|
|
socket.on('listening', common.mustCall(() => {
|
|
socket.close();
|
|
}));
|
|
|
|
socket.on('close', common.mustCall(() => {
|
|
cluster.worker.disconnect();
|
|
}));
|
|
|
|
socket.bind(0);
|
|
}
|