From 9df649e26711bcdb8405c2cd5bb6baa261361619 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 2 Mar 2023 12:38:15 +0100 Subject: [PATCH] perf: cork socket before writing Ensures that headers and chunk len + body can be passed in same packet. Fixes: https://github.com/nodejs/undici/issues/1981 --- lib/client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/client.js b/lib/client.js index 3715d7ead20..b230c368dab 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1668,6 +1668,8 @@ class AsyncWriter { process.emitWarning(new RequestContentLengthMismatchError()) } + socket.cork() + if (bytesWritten === 0) { if (!expectsPayload) { socket[kReset] = true @@ -1688,6 +1690,8 @@ class AsyncWriter { const ret = socket.write(chunk) + socket.uncork() + request.onBodySent(chunk) if (!ret) {