nodejs/test/parallel/test-dgram-bind-socket-close-before-cluster-reply.js
theanarkh f05baff6ad
lib: do not call callback if socket is closed
PR-URL: https://github.com/nodejs/node/pull/52829
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-05-23 20:32:25 +00:00

19 lines
549 B
JavaScript

'use strict';
const common = require('../common');
const dgram = require('dgram');
const cluster = require('cluster');
if (cluster.isPrimary) {
cluster.fork();
} else {
// When the socket attempts to bind, it requests a handle from the cluster.
// Force the cluster to send back an error code.
const socket = dgram.createSocket('udp4');
cluster._getServer = function(self, options, callback) {
socket.close(() => { cluster.worker.disconnect(); });
callback(-1);
};
socket.on('error', common.mustNotCall());
socket.bind();
}