From 8184b1783ae619fe928b2da28456b944a1ea3b0f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 7 May 2023 17:07:28 +0300 Subject: [PATCH] fix: make assertion a noop Not sure how this can occur. I'm guessing if 'finished' and 'drain' are both queued then onDrain will be invoked even though event listeners have been removed. Fixes: https://github.com/nodejs/undici/issues/2109 --- lib/client.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index 688df9e6156..00cffc2846e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1494,9 +1494,11 @@ function writeStream ({ body, client, request, socket, contentLength, header, ex const writer = new AsyncWriter({ socket, request, contentLength, client, expectsPayload, header }) const onData = function (chunk) { - try { - assert(!finished) + if (finished) { + return + } + try { if (!writer.write(chunk) && this.pause) { this.pause() } @@ -1505,7 +1507,9 @@ function writeStream ({ body, client, request, socket, contentLength, header, ex } } const onDrain = function () { - assert(!finished) + if (finished) { + return + } if (body.resume) { body.resume()