node: fix test-net-listen-close-server.js (#17809)

This commit is contained in:
Meghan Denny
2025-02-28 19:24:59 -08:00
committed by GitHub
parent ee6bdc1588
commit 12a2f412fc
3 changed files with 48 additions and 9 deletions

View File

@@ -1407,6 +1407,10 @@ Server.prototype.listen = function listen(port, hostname, onListen) {
throw $ERR_SERVER_ALREADY_LISTEN();
}
if (onListen != null) {
this.once("listening", onListen);
}
try {
var tls = undefined;
var TLSSocketClass = undefined;
@@ -1501,7 +1505,7 @@ Server.prototype[kRealListen] = function realListen(
// That leads to all sorts of confusion.
//
// process.nextTick() is not sufficient because it will run before the IO queue.
setTimeout(emitListeningNextTick, 1, this, onListen?.bind(this));
setTimeout(emitListeningNextTick, 1, this);
};
Server.prototype.getsockname = function getsockname(out) {
@@ -1528,14 +1532,8 @@ class ConnResetException extends Error {
}
}
function emitListeningNextTick(self, onListen) {
if (typeof onListen === "function") {
try {
onListen.$call(self);
} catch (err) {
self.emit("error", err);
}
}
function emitListeningNextTick(self) {
if (!self._handle) return;
self.emit("listening");
}

View File

@@ -0,0 +1,11 @@
'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer(common.mustNotCall());
server.on('close', common.mustCall());
server.listen(0, common.mustNotCall());
server.close('bad argument');

View File

@@ -0,0 +1,30 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer(function(socket) {
});
server.listen(0, common.mustNotCall());
server.on('error', common.mustNotCall());
server.close();