Skip to content

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.

Refs: https://github.com/nodejs/node/pull/2960

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

net

Merge request reports

Loading