Compare commits

...

9 Commits

Author SHA1 Message Date
Alistair Smith
a42a5e2ea3 experiment: pass true 2025-05-06 13:03:44 -07:00
Alistair Smith
9257a7e1ec Merge branch 'main' into ali/fix-test-tls-connect-timeout-option 2025-05-06 12:38:20 -07:00
Alistair Smith
039167acea rm timeout internal prop 2025-05-06 11:43:39 -07:00
Alistair Smith
90b3df2aac types 2025-05-06 11:33:11 -07:00
Alistair Smith
f4d7d7b8e1 Merge branch 'main' of github.com:oven-sh/bun into ali/fix-test-tls-connect-timeout-option 2025-05-06 11:31:10 -07:00
Alistair Smith
52ef449eee slightly improve types 2025-05-06 11:31:06 -07:00
Alistair Smith
307262df49 call SocketHandlers.error 2025-05-06 11:24:00 -07:00
Alistair Smith
333152dd79 works 2025-05-06 11:21:51 -07:00
Alistair Smith
9d602a9087 add test 2025-05-05 16:54:33 -07:00
2 changed files with 32 additions and 6 deletions

View File

@@ -167,7 +167,7 @@ function onConnectEnd() {
}
}
const SocketHandlers: SocketHandler = {
const SocketHandlers = {
close(socket, err) {
const self = socket.data;
if (!self || self[kclosed]) return;
@@ -210,7 +210,7 @@ const SocketHandlers: SocketHandler = {
// we just reuse the same code but we can push null or enqueue right away
SocketEmitEndNT(self);
},
error(socket, error, ignoreHadError) {
error(socket, error, ignoreHadError?: boolean) {
const self = socket.data;
if (!self) return;
if (self._hadError && !ignoreHadError) return;
@@ -279,6 +279,7 @@ const SocketHandlers: SocketHandler = {
if (self._requestCert || self._rejectUnauthorized) {
if (verifyError) {
self.authorized = false;
// TODO: authorizationError should be error instance?
self.authorizationError = verifyError.code || verifyError.message;
if (self._rejectUnauthorized) {
self.destroy(verifyError);
@@ -300,7 +301,8 @@ const SocketHandlers: SocketHandler = {
self.emit("timeout", self);
},
binaryType: "buffer",
};
// TODO: We can improve the type of the socket here
} satisfies SocketHandler<import("node:tls").TLSSocket & { [Key in PropertyKey]: unknown }, "buffer">;
const SocketEmitEndNT = (self, _err?) => {
if (!self[kended]) {
@@ -571,6 +573,10 @@ function Socket(options?) {
signal.addEventListener("abort", destroyWhenAborted.bind(this));
}
}
if (options && typeof options.timeout === "number") {
this.setTimeout(options.timeout);
}
}
$toClass(Socket, "Socket", Duplex);
@@ -707,7 +713,7 @@ Socket.prototype.connect = function connect(...args) {
allowHalfOpen: this.allowHalfOpen,
}).catch(error => {
if (!this.destroyed) {
this.emit("error", error);
SocketHandlers.error(this, error, true);
this.emit("close");
}
});
@@ -875,7 +881,7 @@ Socket.prototype.connect = function connect(...args) {
allowHalfOpen: this.allowHalfOpen,
}).catch(error => {
if (!this.destroyed) {
this.emit("error", error);
SocketHandlers.error(this, error, true);
this.emit("close");
}
});
@@ -890,7 +896,7 @@ Socket.prototype.connect = function connect(...args) {
allowHalfOpen: this.allowHalfOpen,
}).catch(error => {
if (!this.destroyed) {
this.emit("error", error);
SocketHandlers.error(this, error, true);
this.emit("close");
}
});

View File

@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
// This test verifies that `tls.connect()` honors the `timeout` option when the
// socket is internally created.
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
const socket = tls.connect({
port: 42,
lookup: () => {},
timeout: 1000
});
assert.strictEqual(socket.timeout, 1000);