From 8225e7ca68815585eb8c0ddc375b1834201d6d3e Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:17:19 -0500 Subject: [PATCH] Update error handling during TLS connection Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com> --- patches/@types+node+18.15.11.patch | 17 ----------------- ts/util/createHTTPSAgent.ts | 26 ++++++++++++++++---------- 2 files changed, 16 insertions(+), 27 deletions(-) delete mode 100644 patches/@types+node+18.15.11.patch diff --git a/patches/@types+node+18.15.11.patch b/patches/@types+node+18.15.11.patch deleted file mode 100644 index eb135c99c9b..00000000000 --- a/patches/@types+node+18.15.11.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/node_modules/@types/node/tls.d.ts b/node_modules/@types/node/tls.d.ts -index 2c55eb9..a594969 100755 ---- a/node_modules/@types/node/tls.d.ts -+++ b/node_modules/@types/node/tls.d.ts -@@ -621,6 +621,12 @@ declare module 'tls' { - * `identity` must use UTF-8 encoding. - */ - pskCallback?(hint: string | null): PSKCallbackNegotation | null; -+ -+ /* Node.js documentation says: -+ * "...: Any socket.connect() option not already listed." -+ * and "signal" is one of them. -+ */ -+ signal?: AbortSignal; - } - /** - * Accepts encrypted connections using TLS or SSL. diff --git a/ts/util/createHTTPSAgent.ts b/ts/util/createHTTPSAgent.ts index 78ebcc68b44..fb9a2ccd427 100644 --- a/ts/util/createHTTPSAgent.ts +++ b/ts/util/createHTTPSAgent.ts @@ -145,16 +145,22 @@ export async function happyEyeballs({ v6Attempts += 1; } - const socket = await pTimeout( - connect({ - address: addr.address, - port, - tlsOptions, - abortSignal: abortController.signal, - }), - CONNECT_TIMEOUT_MS, - 'createHTTPSAgent.connect: connection timed out' - ); + let socket: net.Socket; + try { + socket = await pTimeout( + connect({ + address: addr.address, + port, + tlsOptions, + abortSignal: abortController.signal, + }), + CONNECT_TIMEOUT_MS, + 'createHTTPSAgent.connect: connection timed out' + ); + } catch (error) { + abortController.abort(); + throw error; + } if (abortController.signal.aborted) { throw new Error('Aborted');