mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
node: fix test-net-connect-reset.js (#17823)
This commit is contained in:
@@ -1635,6 +1635,10 @@ JSC_DEFINE_HOST_FUNCTION(Bun::jsFunctionMakeErrorWithCode, (JSC::JSGlobalObject
|
||||
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));
|
||||
case ErrorCode::ERR_SOCKET_CLOSED:
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_SOCKET_CLOSED, "Socket is closed"_s));
|
||||
case ErrorCode::ERR_SOCKET_CLOSED_BEFORE_CONNECTION:
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_SOCKET_CLOSED_BEFORE_CONNECTION, "Socket closed before the connection was established"_s));
|
||||
|
||||
default: {
|
||||
break;
|
||||
|
||||
2
src/js/builtins.d.ts
vendored
2
src/js/builtins.d.ts
vendored
@@ -636,6 +636,8 @@ 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;
|
||||
declare function $ERR_SOCKET_CLOSED(): Error;
|
||||
declare function $ERR_SOCKET_CLOSED_BEFORE_CONNECTION(): Error;
|
||||
|
||||
/**
|
||||
* Convert a function to a class-like object.
|
||||
|
||||
@@ -1007,6 +1007,11 @@ const Socket = (function (InternalSocket) {
|
||||
}
|
||||
}
|
||||
|
||||
_reset() {
|
||||
this.resetAndClosing = true;
|
||||
return this.destroy();
|
||||
}
|
||||
|
||||
get readyState() {
|
||||
if (this.connecting) return "opening";
|
||||
if (this.readable) {
|
||||
@@ -1037,13 +1042,14 @@ const Socket = (function (InternalSocket) {
|
||||
resetAndDestroy() {
|
||||
if (this._handle) {
|
||||
if (this.connecting) {
|
||||
this.once("connect", () => this._handle?.terminate());
|
||||
this.once("connect", () => this._reset());
|
||||
} else {
|
||||
this._handle.terminate();
|
||||
this._reset();
|
||||
}
|
||||
} else {
|
||||
this.destroy($ERR_SOCKET_CLOSED_BEFORE_CONNECTION("ERR_SOCKET_CLOSED_BEFORE_CONNECTION"));
|
||||
this.destroy($ERR_SOCKET_CLOSED());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
setKeepAlive(enable = false, initialDelayMsecs = 0) {
|
||||
@@ -1155,7 +1161,7 @@ const Socket = (function (InternalSocket) {
|
||||
this._pendingData = chunk;
|
||||
this._pendingEncoding = encoding;
|
||||
function onClose() {
|
||||
callback($ERR_SOCKET_CLOSED_BEFORE_CONNECTION("ERR_SOCKET_CLOSED_BEFORE_CONNECTION"));
|
||||
callback($ERR_SOCKET_CLOSED_BEFORE_CONNECTION());
|
||||
}
|
||||
this.once("connect", function connect() {
|
||||
this.off("close", onClose);
|
||||
@@ -1168,7 +1174,7 @@ const Socket = (function (InternalSocket) {
|
||||
this.#writeCallback = null;
|
||||
const socket = this._handle;
|
||||
if (!socket) {
|
||||
callback($ERR_SOCKET_CLOSED("Socket is closed"));
|
||||
callback($ERR_SOCKET_CLOSED());
|
||||
return false;
|
||||
}
|
||||
const success = socket.$write(chunk, encoding);
|
||||
|
||||
13
test/js/node/test/parallel/test-net-connect-reset.js
Normal file
13
test/js/node/test/parallel/test-net-connect-reset.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const net = require('net');
|
||||
|
||||
const socket = new net.Socket();
|
||||
socket.resetAndDestroy();
|
||||
// Emit error if socket is not connecting/connected
|
||||
socket.on('error', common.mustCall(
|
||||
common.expectsError({
|
||||
code: 'ERR_SOCKET_CLOSED',
|
||||
name: 'Error'
|
||||
}))
|
||||
);
|
||||
Reference in New Issue
Block a user