node/test/parallel/test-dgram-bind-socket-close-before-lookup.js
theanarkh d405a606ab
lib: return directly if udp socket close before lookup
PR-URL: https://github.com/nodejs/node/pull/51914
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-03-01 19:09:07 +00:00

20 lines
519 B
JavaScript

'use strict';
const common = require('../common');
const dgram = require('dgram');
// Do not emit error event in callback which is called by lookup when socket is closed
const socket = dgram.createSocket({
type: 'udp4',
lookup: (...args) => {
// Call lookup callback after 1s
setTimeout(() => {
args.at(-1)(new Error('an error'));
}, 1000);
}
});
socket.on('error', common.mustNotCall());
socket.bind(12345, 'localhost');
// Close the socket before calling DNS lookup callback
socket.close();