net: fix bufferSize

bufferSize should only look at writableLength otherwise it will
always show more than what is actually pending.

PR-URL: https://github.com/nodejs/node/pull/34088
Refs: https://github.com/nodejs/node/issues/34078
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Robert Nagy 2020-06-27 19:39:04 +02:00
parent 8f4b4f272e
commit 312a4f3255
3 changed files with 3 additions and 3 deletions

View File

@ -541,7 +541,7 @@ ObjectDefineProperty(Socket.prototype, 'readyState', {
ObjectDefineProperty(Socket.prototype, 'bufferSize', {
get: function() {
if (this._handle) {
return this[kLastWriteQueueSize] + this.writableLength;
return this.writableLength;
}
}
});

View File

@ -31,7 +31,7 @@ server.listen(0, common.mustCall(() => {
for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i + 1);
assert.strictEqual(client.bufferSize, i);
}
client.on('finish', common.mustCall(() => {

View File

@ -56,7 +56,7 @@ const net = require('net');
for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i + 1);
assert.strictEqual(client.bufferSize, i);
}
client.on('end', common.mustCall());