From e18fa04ae7bbfa31da830cc429ddfe84d251acb1 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 27 Jun 2020 19:39:04 +0200 Subject: [PATCH 1/2] net: fix bufferSize bufferSize should only look at writableLength otherwise it will always show more than what is actually pending. --- lib/net.js | 2 +- test/parallel/test-tls-buffersize.js | 2 +- test/parallel/test-tls-streamwrap-buffersize.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/net.js b/lib/net.js index 9c5393bd28504b..54958d5912e8fa 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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; } } }); diff --git a/test/parallel/test-tls-buffersize.js b/test/parallel/test-tls-buffersize.js index c94b95d7b32d31..eadd4cb1e40c9e 100644 --- a/test/parallel/test-tls-buffersize.js +++ b/test/parallel/test-tls-buffersize.js @@ -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(() => { diff --git a/test/parallel/test-tls-streamwrap-buffersize.js b/test/parallel/test-tls-streamwrap-buffersize.js index 984cc51e505183..0e0a49883a5a08 100644 --- a/test/parallel/test-tls-streamwrap-buffersize.js +++ b/test/parallel/test-tls-streamwrap-buffersize.js @@ -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()); From 45be1c87e36e4a3414d33eabb50ec290dfdf23ae Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 28 Jun 2020 14:44:38 +0200 Subject: [PATCH 2/2] net: doc deprecate bufferSize --- doc/api/deprecations.md | 15 +++++++++++++++ doc/api/net.md | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 274c4cdfd26fb7..6875cc74345bb3 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2751,6 +2751,19 @@ const moduleParents = Object.values(require.cache) .filter((m) => m.children.includes(module)); ``` + +### DEP0XXX: `socket.bufferSize` + + +Type: Documentation-only + +[`socket.bufferSize`][] is just an alias for [`writable.writableLength`][]. + [`--pending-deprecation`]: cli.html#cli_pending_deprecation [`--throw-deprecation`]: cli.html#cli_throw_deprecation [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size @@ -2824,6 +2837,7 @@ const moduleParents = Object.values(require.cache) [`script.createCachedData()`]: vm.html#vm_script_createcacheddata [`setInterval()`]: timers.html#timers_setinterval_callback_delay_args [`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args +[`socket.bufferSize`]: net.html#net_socket_buffersize [`timeout.ref()`]: timers.html#timers_timeout_ref [`timeout.refresh()`]: timers.html#timers_timeout_refresh [`timeout.unref()`]: timers.html#timers_timeout_unref @@ -2860,6 +2874,7 @@ const moduleParents = Object.values(require.cache) [`util`]: util.html [`worker.exitedAfterDisconnect`]: cluster.html#cluster_worker_exitedafterdisconnect [`worker.terminate()`]: worker_threads.html#worker_threads_worker_terminate +[`writable.writableLength`]: stream.html#stream_writable_writablelength [`zlib.bytesWritten`]: zlib.html#zlib_zlib_byteswritten [Legacy URL API]: url.html#url_legacy_url_api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf diff --git a/doc/api/net.md b/doc/api/net.md index b9813aae885293..a07c34cee07835 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -529,8 +529,12 @@ socket as reported by the operating system: ### `socket.bufferSize` +> Stability: 0 - Deprecated: Use [`writable.writableLength`][] instead. + * {integer} This property shows the number of characters buffered for writing. The buffer @@ -1268,6 +1272,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`. [`socket.setEncoding()`]: #net_socket_setencoding_encoding [`socket.setTimeout()`]: #net_socket_settimeout_timeout_callback [`socket.setTimeout(timeout)`]: #net_socket_settimeout_timeout_callback +[`writable.writableLength`]: stream.html#stream_writable_writablelength [`writable.destroyed`]: stream.html#stream_writable_destroyed [`writable.destroy()`]: stream.html#stream_writable_destroy_error [`writable.end()`]: stream.html#stream_writable_end_chunk_encoding_callback