mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
node: fix test-net-server-call-listen-multiple-times.js (#17785)
This commit is contained in:
@@ -1443,6 +1443,8 @@ JSC_DEFINE_HOST_FUNCTION(Bun::jsFunctionMakeErrorWithCode, (JSC::JSGlobalObject
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, "Illegal constructor"_s));
|
||||
case ErrorCode::ERR_DIR_CLOSED:
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_DIR_CLOSED, "Directory handle was closed"_s));
|
||||
case ErrorCode::ERR_SERVER_ALREADY_LISTEN:
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_SERVER_ALREADY_LISTEN, "Listen method has been called more than once without closing."_s));
|
||||
|
||||
default: {
|
||||
break;
|
||||
|
||||
@@ -83,6 +83,7 @@ const errors: ErrorCodeMapping = [
|
||||
["ERR_ZLIB_INITIALIZATION_FAILED", Error],
|
||||
["ERR_INVALID_CHAR", TypeError],
|
||||
["MODULE_NOT_FOUND", Error],
|
||||
["ERR_SERVER_ALREADY_LISTEN", Error],
|
||||
|
||||
// Bun-specific
|
||||
["ERR_FORMDATA_PARSE_ERROR", TypeError],
|
||||
|
||||
1
src/js/builtins.d.ts
vendored
1
src/js/builtins.d.ts
vendored
@@ -629,6 +629,7 @@ declare function $ERR_STREAM_UNSHIFT_AFTER_END_EVENT(): Error;
|
||||
declare function $ERR_STREAM_PUSH_AFTER_EOF(): Error;
|
||||
declare function $ERR_STREAM_UNABLE_TO_PIPE(): Error;
|
||||
declare function $ERR_ILLEGAL_CONSTRUCTOR(): TypeError;
|
||||
declare function $ERR_SERVER_ALREADY_LISTEN(): Error;
|
||||
|
||||
/**
|
||||
* Convert a function to a class-like object.
|
||||
|
||||
@@ -1403,6 +1403,10 @@ Server.prototype.listen = function listen(port, hostname, onListen) {
|
||||
hostname = hostname || "::";
|
||||
}
|
||||
|
||||
if (this._handle) {
|
||||
throw $ERR_SERVER_ALREADY_LISTEN();
|
||||
}
|
||||
|
||||
try {
|
||||
var tls = undefined;
|
||||
var TLSSocketClass = undefined;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
|
||||
// First test. Check that after error event you can listen right away.
|
||||
{
|
||||
const dummyServer = net.Server();
|
||||
const server = net.Server();
|
||||
|
||||
// Run some server in order to simulate EADDRINUSE error.
|
||||
dummyServer.listen(common.mustCall(() => {
|
||||
// Try to listen used port.
|
||||
server.listen(dummyServer.address().port);
|
||||
}));
|
||||
|
||||
server.on('error', common.mustCall((e) => {
|
||||
server.listen(common.mustCall(() => {
|
||||
dummyServer.close();
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
// Second test. Check that second listen call throws an error.
|
||||
{
|
||||
const server = net.Server();
|
||||
|
||||
server.listen(common.mustCall(() => server.close()));
|
||||
|
||||
assert.throws(() => server.listen(), {
|
||||
code: 'ERR_SERVER_ALREADY_LISTEN',
|
||||
name: 'Error'
|
||||
});
|
||||
}
|
||||
|
||||
// Third test.
|
||||
// Check that after the close call you can run listen method just fine.
|
||||
{
|
||||
const server = net.Server();
|
||||
|
||||
server.listen(common.mustCall(() => {
|
||||
server.close();
|
||||
server.listen(common.mustCall(() => server.close()));
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user