-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: increase highWaterMark value to fix file descriptor issue on v16+ #389
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a unit test?
@mcollina after other tests, the behavior described above is happening when using const http = require('http')
http.createServer(function (req, res) {
res.end('Hello, World!\n')
}).listen(3000) it works fine. So, it might need some other discoveries. Firstly, would you mind elaborating why do you think that it's a bug inside |
My read of this is that something changed in node core and Bubbleprof needs to be updated. If it is a bug in Node core, we'd need to work around it anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
After a long time spent on this, I don't think we can actually fix it before our deadline. There is likely a node core bug (we need to get back to it)
I was debugging inside node core and I have found that https://github.com/nodejs/node/blob/ce4d3adf5029278090bdfca8e2b8a2fc384b9cc6/lib/internal/streams/writable.js#L733 returns It might be a bug inside backpressure streams or it might be missing a warning to tell the users what they should do in that situation, for instance, when there is no listener for Why it appears on v15.9.0+?The nodejs/node#37300 adds
We are now written way more than in the old versions because of
In that case, we can either handle the By the docs:
Note: Would be great to create an easily reproducible example to tag in an issue inside Node.js for that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@RafaelGSS why do you think this is an issue in Node core? |
We have solved it in bubbleprof by just increasing the As mentioned above, this bug might exist in old versions of Node.js as well, the difference is that in the old versions we were not dispatching too many events at the same time. When the is that clear for you? |
Yes, the explanation is clear. Yet, it feels like a stream that's raising the end event before all data has been read would be such an obvious bug that I wound find it really odd that this wasn't caught in Node's own tests. |
I wonder if this isn't more likely to be a bug in the implementation of our decoder transform stream (which extends AbstractDecoder, which in turn contains the whole of the implementation). For some reason it may not be respecting the invariants that Node expects. I haven't looked into it though. |
Firstly, the issue is not in the decoder because the behavior happens in the encoder. We have removed the decoder and added a breaking point inside of it, and it doesn't work (never calls). We have also tested without the encoder (just passing through) and the bug is still there. One thing that we have discovered is that if we reduce the amount of data written at the same time it works. For instance, I have changed it to: _transform (message, encoding, callback) {
- const messageLength = this._messageType.encodingLength(message)
- const framedMessage = Buffer.alloc(messageLength + FRAME_PREFIX_SIZE)
- framedMessage.writeUInt32BE(messageLength, 0)
- this._messageType.encode(message, framedMessage, FRAME_PREFIX_SIZE)
- callback(null, framedMessage)
+ callback(null, "example message")
} and works fine, but if I change it to - callback(null, "example message")
+ callback(null, JSON.stringify(message)) it doesn't work again. Note: one thing important to mention is not because the
Also, look at one example for Node.js docs: // Write the data to the supplied writable stream one million times.
// Be attentive to back-pressure.
function writeOneMillionTimes(writer, data, encoding, callback) {
let i = 1000000;
write();
function write() {
let ok = true;
do {
i--;
if (i === 0) {
// Last time!
writer.write(data, encoding, callback);
} else {
// See if we should continue, or wait.
// Don't pass the callback, because we're not done yet.
ok = writer.write(data, encoding);
}
} while (i > 0 && ok);
if (i > 0) {
// Had to stop early!
// Write some more once it drains.
writer.once('drain', write);
}
}
} So, in the first moment, the current behavior looks expected, however, I don't think being quiet when it happens is doable, I feel that Node.js should emit a warning when a |
Those affirmations were gotten from my debugging phrase in bubbleprof. But, for sure if I could create an easily reproducible code and share it on Node.js we could have more insights about that. |
It aims to solve: clinicjs/node-clinic#293 (comment).
However, I'm not entirely sure if it's the best approach, It was not documented anywhere in nodejs streams documentation but it aims to solve the behavior added in
v15.9.0
I'm doing some tests to see if it affects the result data.
Important: see #389 (comment)