Skip to content

Commit c348000

Browse files
committed
lib: return directly if udp socket close before lookup
1 parent 1263bb6 commit c348000

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/dgram.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
328328

329329
// Resolve address first
330330
state.handle.lookup(address, (err, ip) => {
331+
if (!state.handle)
332+
return; // Handle has been closed in the mean time
333+
331334
if (err) {
332335
state.bindState = BIND_STATE_UNBOUND;
333336
this.emit('error', err);
@@ -356,9 +359,6 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
356359
this.emit('error', ex);
357360
});
358361
} else {
359-
if (!state.handle)
360-
return; // Handle has been closed in the mean time
361-
362362
const err = state.handle.bind(ip, port || 0, flags);
363363
if (err) {
364364
const ex = new ExceptionWithHostPort(err, 'bind', ip, port);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const common = require('../common');
3+
const dgram = require('dgram');
4+
5+
const socket = dgram.createSocket({
6+
type: 'udp4',
7+
lookup: (...args) => {
8+
setTimeout(() => {
9+
args[args.length - 1](new Error('an error'));
10+
}, 1000);
11+
}
12+
});
13+
14+
socket.on('error', common.mustNotCall());
15+
socket.bind(12345, 'localhost');
16+
socket.close();

0 commit comments

Comments
 (0)