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 — dgram: don't swallow bind errors when callback is provided · nodejs/node@04dfefe

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • dgram.js
  • test/parallel
    • test-dgram-bind-error-callback.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
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
296296
const cb = arguments.length && arguments[arguments.length - 1];
297297
if (typeof cb === 'function') {
298298
function removeListeners() {
299-
this.removeListener('error', removeListeners);
299+
this.removeListener(EventEmitter.errorMonitor, removeListeners);
300300
this.removeListener('listening', onListening);
301301
}
302302

@@ -305,7 +305,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
305305
FunctionPrototypeCall(cb, this);
306306
}
307307

308-
this.on('error', removeListeners);
308+
this.on(EventEmitter.errorMonitor, removeListeners);
309309
this.on('listening', onListening);
310310
}
311311

Collapse file

‎test/parallel/test-dgram-bind-error-callback.js‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('node:assert');
4+
const dgram = require('node:dgram');
5+
6+
// Ensure that bind errors (e.g. EADDRINUSE) are not silently swallowed
7+
// when socket.bind() is called with a callback but without a user
8+
// 'error' handler.
9+
10+
const socket1 = dgram.createSocket('udp4');
11+
12+
socket1.bind(0, common.mustCall(() => {
13+
const { port } = socket1.address();
14+
const socket2 = dgram.createSocket('udp4');
15+
16+
process.on('uncaughtException', common.mustCall((err) => {
17+
assert.strictEqual(err.code, 'EADDRINUSE');
18+
socket1.close();
19+
socket2.close();
20+
}));
21+
22+
socket2.bind({ port }, common.mustNotCall());
23+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.