1// Flags: --expose-internals 2'use strict'; 3const common = require('../common'); 4const assert = require('assert'); 5const cluster = require('cluster'); 6const dgram = require('dgram'); 7const { internalBinding } = require('internal/test/binding'); 8const { UV_UNKNOWN } = internalBinding('uv'); 9 10if (cluster.isPrimary) { 11 cluster.fork(); 12} else { 13 // When the socket attempts to bind, it requests a handle from the cluster. 14 // Force the cluster to send back an error code. 15 cluster._getServer = function(self, options, callback) { 16 callback(UV_UNKNOWN); 17 }; 18 19 const socket = dgram.createSocket('udp4'); 20 21 socket.on('error', common.mustCall((err) => { 22 assert.match(err.toString(), /^Error: bind UNKNOWN 0\.0\.0\.0$/); 23 process.nextTick(common.mustCall(() => { 24 assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND 25 socket.close(); 26 cluster.worker.disconnect(); 27 })); 28 })); 29 30 socket.bind(common.mustNotCall('Socket should not bind.')); 31} 32