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 metcoder95 committed Jul 21, 2023
1 parent 59fdfa3 commit eb79a7a
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 eb79a7a

Please sign in to comment.