Commit 85a5e5a1 authored by Brendan Ashworth's avatar Brendan Ashworth
Browse files

net: fix bytesWritten during writev

When a writev is caused on a socket (sometimes through corking and
uncorking), previously net would call Buffer.byteLength on the array of
buffers and chunks. This throws a TypeError, because Buffer.byteLength
throws when passed a non-string.

In dbfe8c4e, behavior changed to throw when passed a non-string. This is
correct behavior. Previously, it would cast the argument to a string, so
before this commit, bytesWritten would give an erroneous value. This
commit corrects the behavior equally both before and after dbfe8c4e.

This commit fixes this bug by iterating over each chunk in the pending
stack and calculating the length individually. Also adds a regression
test. This additionally changes an `instanceof Buffer` check to `typeof
!== 'string'`, which should be equivalent.

PR-URL: https://github.com/nodejs/node/pull/14236


Reviewed-By: default avatarBrian White <mscdex@mscdex.net>
Reviewed-By: default avatarLuigi Pinca <luigipinca@gmail.com>
Reviewed-By: default avatarTobias Nießen <tniessen@tnie.de>
Refs: https://github.com/nodejs/node/pull/2960
parent 75bf8a9d
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment