Uh oh!
There was an error while loading. Please reload this page.
net: fix bufferSize - #34088
Conversation
ronag
commented
Jun 27, 2020
@nodejs/net |
There was a problem hiding this comment.
writableLength won't get subtracted until the write actually completes. Not sure what the purpose of kLastWriteQueueSize is here.
There was a problem hiding this comment.
This is my understanding: assume there is nothing buffered so writableLength is zero and there is a write in progress, socket.bufferSize should report the number of bytes that are currently being written and not zero.
There was a problem hiding this comment.
I don't think writableLength is zero here, it becomes non zero as soon as you do write() and won't become zero again unless all writes have finished
should report the number of bytes that are currently being writte
writableLength does exactly that as far as I can tell
There was a problem hiding this comment.
Ok, can you check when this was originally added? The original commit might shed some light.
There was a problem hiding this comment.
Perhaps at that time writableLength wasn't working like this? I don't know.
There was a problem hiding this comment.
The only explanation I can think of is if the callback is called before the write has actually completed... which would be a bit weird.
There was a problem hiding this comment.
Right, I don’t think that that’s what happens (but I guess it could be checked easily enough through verifying that the write queue size is 0 when we get the callback from libuv?)
There was a problem hiding this comment.
Seems like handle.writeQueueSize is not zero before invoking the callback. Which is kind of confusing.
There was a problem hiding this comment.
@addaleax the following assertion will fail when running the test suite:
diff--gita/lib/internal/stream_base_commons.jsb/lib/internal/stream_base_commons.jsindexfdf540a47e..4c7049bf51100644---a/lib/internal/stream_base_commons.js+++b/lib/internal/stream_base_commons.js
@@ -30,6+30,7 @@ const{}=require('internal/timers');const{ isUint8Array }=require('internal/util/types');const{ clearTimeout }=require('timers');+constassert=require('assert');constkMaybeDestroy=Symbol('kMaybeDestroy');constkUpdateTimer=Symbol('kUpdateTimer');
@@ -104,6+105,8 @@ functiononWriteComplete(status){stream[kUpdateTimer]();stream[kAfterAsyncWrite](this);+assert(this.handle.writeQueueSize===0);+if(typeofthis.callback==='function')this.callback(null);}addaleax
commented
Jun 27, 2020
This code seemed a bit suspicious to me as well, but anytime I changed something, CI broke, so … I’ll kick off CI 😄 |
nodejs-github-bot
commented
Jun 27, 2020
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
Jun 27, 2020
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
Jun 27, 2020
nodejs-github-bot
commented
Jun 27, 2020
So from what I can tell Furthermore, this causes a problem since |
addaleax
commented
Jun 27, 2020
@ronag Maybe the problem is a discrepancy between This diff doesn’t result in any obvious crashes: --- a/src/stream_wrap.cc+++ b/src/stream_wrap.cc@@ -400,6 +400,7 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) {
CHECK_NOT_NULL(req_wrap);
HandleScope scope(req_wrap->env()->isolate());
Context::Scope context_scope(req_wrap->env()->context());
+ CHECK_EQ(static_cast<LibuvStreamWrap*>(req_wrap->stream())->stream()->write_queue_size, 0);
req_wrap->Done(status);
}
|
This comment has been minimized.
This comment has been minimized.
addaleax
commented
Jun 27, 2020
My understanding is that it is the size of the currently active write. This is not necessarily equivalent to the size of the last scheduled write, because sometimes a large write is only partially written and then the rest of it. libuv communicated that through
Are you talking about a |
diff --git a/test/parallel/test-tls-streamwrap-buffersize.js b/test/parallel/test-tls-streamwrap-buffersize.js
index 984cc51e50..6ec028c621 100644
--- a/test/parallel/test-tls-streamwrap-buffersize.js+++ b/test/parallel/test-tls-streamwrap-buffersize.js@@ -52,6 +52,7 @@ const net = require('net');
socket,
rejectUnauthorized: false,
}, common.mustCall(() => {
+ assert.strictEqual(client._handle.writeQueueSize, 0);
assert.strictEqual(client.bufferSize, 0);
for (let i = 1; i < iter; i++) {AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
80 !== 0
at TLSSocket.<anonymous> (/Users/ronagy/GitHub/nxtedition/node/test/parallel/test-tls-streamwrap-buffersize.js:55:16)
at TLSSocket.<anonymous> (/Users/ronagy/GitHub/nxtedition/node/test/common/index.js:365:15)
at Object.onceWrapper (events.js:420:28)
at TLSSocket.emit (events.js:314:20)
at TLSSocket.onConnectSecure (_tls_wrap.js:1523:10)
at TLSSocket.emit (events.js:314:20)
at TLSSocket._finishInit (_tls_wrap.js:933:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:707:12)
at DuplexSocket.ondata (internal/js_stream_socket.js:77:22)
at DuplexSocket.emit (events.js:314:20) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 80,
expected: 0,
operator: 'strictEqual'
} |
This comment has been minimized.
This comment has been minimized.
ronag
commented
Jun 27, 2020
@addaleax Are we in agreement on |
This comment has been minimized.
This comment has been minimized.
ronag
commented
Jun 27, 2020
Maybe something to do with tls handshake or something? |
nodejs-github-bot
commented
Jun 27, 2020
ronag
commented
Jun 27, 2020
@addaleax Regarding |
ronag
commented
Jun 29, 2020
are deprecations always semver-major? |
richardlau
commented
Jun 29, 2020
Generally yes (for non-doc-only deprecations) unless the TSC make an exception: https://github.com/nodejs/node/blob/master/doc/guides/collaborator-guide.md#deprecations |
ronag
commented
Jun 30, 2020
Landed in 8f4b4f2...0edeeec |
bufferSize should only look at writableLength otherwise it will always show more than what is actually pending.
I'm not familiar with this code but it just looks wrong/suspicious to me.
Tests seem to pass with changes.
Maybe someone more familiar could take a look at determine whether this seems reasonable and what a good test could be?
Refs: #34078
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes