Skip to content

Commit

Permalink
perf: cork socket before writing (nodejs#1982)
Browse files Browse the repository at this point in the history
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: nodejs#1981
  • Loading branch information
ronag authored and crysmags committed Feb 27, 2024
1 parent 0f96f7d commit 84b2ddd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,8 @@ class AsyncWriter {
process.emitWarning(new RequestContentLengthMismatchError())
}

socket.cork()

if (bytesWritten === 0) {
if (!expectsPayload) {
socket[kReset] = true
Expand All @@ -1688,6 +1690,8 @@ class AsyncWriter {

const ret = socket.write(chunk)

socket.uncork()

request.onBodySent(chunk)

if (!ret) {
Expand Down

0 comments on commit 84b2ddd

Please sign in to comment.