From a1322fd96c1f033c0f93dd8f44a03a729fe4b63a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 20 Jan 2023 10:07:47 +0100 Subject: [PATCH] fix: don't set socket on client before init Refs: https://github.com/nodejs/undici/discussions/1633 --- lib/client.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/client.js b/lib/client.js index 41fd4a753f8..1317fc4d686 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1074,8 +1074,6 @@ async function connect (client) { assert(socket) - client[kSocket] = socket - socket[kNoRef] = false socket[kWriting] = false socket[kReset] = false @@ -1091,6 +1089,8 @@ async function connect (client) { .on('end', onSocketEnd) .on('close', onSocketClose) + client[kSocket] = socket + if (channels.connected.hasSubscribers) { channels.connected.publish({ connectParams: { @@ -1176,7 +1176,7 @@ function _resume (client, sync) { const socket = client[kSocket] - if (socket) { + if (socket && !socket.destroyed) { if (client[kSize] === 0) { if (!socket[kNoRef] && socket.unref) { socket.unref() @@ -1243,7 +1243,7 @@ function _resume (client, sync) { if (!socket) { connect(client) - continue + return } if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {