From c9c07b3a63d1319c96b91f9587f3139fdf985b90 Mon Sep 17 00:00:00 2001 From: Wai Ho Choy Date: Sat, 19 Oct 2024 23:12:11 -0700 Subject: [PATCH 1/2] fix: handle undefined deref of weakref socket --- lib/core/connect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/connect.js b/lib/core/connect.js index 8ab21fcd5fc..de27c7aa4ff 100644 --- a/lib/core/connect.js +++ b/lib/core/connect.js @@ -221,7 +221,7 @@ const setupConnectTimeout = process.platform === 'win32' */ function onConnectTimeout (socket, opts) { let message = 'Connect Timeout Error' - if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) { + if (Array.isArray(socket?.autoSelectFamilyAttemptedAddresses)) { message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(', ')},` } else { message += ` (attempted address: ${opts.hostname}:${opts.port},` From 022e2ef9a2d785a19de8fed05a66ed7e8837e52c Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sun, 3 Nov 2024 20:39:31 +0100 Subject: [PATCH 2/2] exit early --- lib/core/connect.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/connect.js b/lib/core/connect.js index de27c7aa4ff..8cd8abccc54 100644 --- a/lib/core/connect.js +++ b/lib/core/connect.js @@ -220,8 +220,13 @@ const setupConnectTimeout = process.platform === 'win32' * @param {number} opts.port */ function onConnectTimeout (socket, opts) { + // The socket could be already garbage collected + if (socket == null) { + return + } + let message = 'Connect Timeout Error' - if (Array.isArray(socket?.autoSelectFamilyAttemptedAddresses)) { + if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) { message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(', ')},` } else { message += ` (attempted address: ${opts.hostname}:${opts.port},`