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>
This commit is contained in:
parent
00dc6d9d97
commit
d405a606ab
@ -328,6 +328,9 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
|
|||||||
|
|
||||||
// Resolve address first
|
// Resolve address first
|
||||||
state.handle.lookup(address, (err, ip) => {
|
state.handle.lookup(address, (err, ip) => {
|
||||||
|
if (!state.handle)
|
||||||
|
return; // Handle has been closed in the mean time
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
state.bindState = BIND_STATE_UNBOUND;
|
state.bindState = BIND_STATE_UNBOUND;
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
@ -356,9 +359,6 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
|
|||||||
this.emit('error', ex);
|
this.emit('error', ex);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (!state.handle)
|
|
||||||
return; // Handle has been closed in the mean time
|
|
||||||
|
|
||||||
const err = state.handle.bind(ip, port || 0, flags);
|
const err = state.handle.bind(ip, port || 0, flags);
|
||||||
if (err) {
|
if (err) {
|
||||||
const ex = new ExceptionWithHostPort(err, 'bind', ip, port);
|
const ex = new ExceptionWithHostPort(err, 'bind', ip, port);
|
||||||
|
19
test/parallel/test-dgram-bind-socket-close-before-lookup.js
Normal file
19
test/parallel/test-dgram-bind-socket-close-before-lookup.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'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();
|
Loading…
x
Reference in New Issue
Block a user