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(', ')},`