From f98fbef4a990ec74c871ddbd3454472ee0355670 Mon Sep 17 00:00:00 2001 From: hochoy Date: Mon, 11 Nov 2024 11:29:55 -0800 Subject: [PATCH] fix: handle undefined deref() of WeakRef(socket) (#3751) * fix: handle undefined deref of weakref socket * exit early --------- Co-authored-by: Aras Abbasi --- 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(', ')},`