GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: return directly if udp socket close before lookup · nodejs/node@fcc6d54

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • dgram.js
  • test/parallel
    • test-dgram-bind-socket-close-before-lookup.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/dgram.js‎

Copy file name to clipboardExpand all lines: lib/dgram.js
+3-3Lines 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);
Collapse file

‎test/parallel/test-dgram-bind-socket-close-before-lookup.js‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
const common = require('../common');
3+
const dgram = require('dgram');
4+
5+
// Do not emit error event in callback which is called by lookup when socket is closed
6+
const socket = dgram.createSocket({
7+
type: 'udp4',
8+
lookup: (...args) => {
9+
// Call lookup callback after 1s
10+
setTimeout(() => {
11+
args.at(-1)(new Error('an error'));
12+
}, 1000);
13+
}
14+
});
15+
16+
socket.on('error', common.mustNotCall());
17+
socket.bind(12345, 'localhost');
18+
// Close the socket before calling DNS lookup callback
19+
socket.close();

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.