From 98d1b1b2bdbe6137d4b4156b5fbe33af44bdb293 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:45:51 +0100 Subject: [PATCH] fix: handle undefined deref() of WeakRef(socket) (#3751) (#3822) * fix: handle undefined deref of weakref socket * exit early --------- Co-authored-by: Aras Abbasi (cherry picked from commit f98fbef4a990ec74c871ddbd3454472ee0355670) Co-authored-by: hochoy --- lib/core/connect.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/core/connect.js b/lib/core/connect.js index 8ab21fcd5fc..8cd8abccc54 100644 --- a/lib/core/connect.js +++ b/lib/core/connect.js @@ -220,6 +220,11 @@ 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)) { message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(', ')},`