mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
node: fix test-net-listen-close-server.js (#17809)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
30
test/js/node/test/parallel/test-net-listen-close-server.js
Normal file
30
test/js/node/test/parallel/test-net-listen-close-server.js
Normal 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();
|
||||
Reference in New Issue
Block a user