1'use strict'; 2const common = require('../common'); 3if (common.isWindows) 4 common.skip('dgram clustering is currently not supported on windows.'); 5 6const assert = require('assert'); 7const cluster = require('cluster'); 8const dgram = require('dgram'); 9 10if (cluster.isPrimary) { 11 cluster.fork(); 12} else { 13 // When the socket attempts to bind, it requests a handle from the cluster. 14 // Close the socket before returning the handle from the cluster. 15 const socket = dgram.createSocket('udp4'); 16 const _getServer = cluster._getServer; 17 18 cluster._getServer = common.mustCall(function(self, options, callback) { 19 socket.close(common.mustCall(() => { 20 _getServer.call(this, self, options, common.mustCall((err, handle) => { 21 assert.strictEqual(err, 0); 22 23 // When the socket determines that it was already closed, it will 24 // close the handle. Use handle.close() to terminate the test. 25 const close = handle.close; 26 27 handle.close = common.mustCall(function() { 28 setImmediate(() => cluster.worker.disconnect()); 29 return close.call(this); 30 }); 31 32 callback(err, handle); 33 })); 34 })); 35 }); 36 37 socket.bind(common.mustNotCall('Socket should not bind.')); 38} 39