diff --git a/lib/client.js b/lib/client.js index faf5124a975..91ebe3cfc18 100644 --- a/lib/client.js +++ b/lib/client.js @@ -51,20 +51,7 @@ function connect (client) { }) } -function destroyMaybe (client) { - if ( - client.closed && - !client[kLastBody] && - client[kQueue].length() === 0 && - client[kInflight].length === 0 - ) { - client.destroy() - } -} - function reconnect (client, err) { - err = err || new Error('premature close') - if (client[kLastBody]) { client[kLastBody].destroy(err) client[kLastBody] = null @@ -427,6 +414,17 @@ function parseHeaders (headers) { module.exports = Client +function destroyMaybe (client) { + if ( + client.closed && + !client._lastBody && + client[kQueue].length() === 0 && + client[kCallbacks].length === 0 + ) { + client.destroy() + } +} + function destroySocket (socket, err, cb) { // This code is basically the same as... // stream.finished(socket, er => cb(err || er))