Closed
Description
Version
16.4.2
Platform
Windows 10
Subsystem
No response
What steps will reproduce the bug?
I am reading specific lengths of data off the readable queue. I check the readableLength to determine how much data I can read.
However, there are occasions when the readable event triggers but the readableLength is returned as zero.
client._socket.on("readable", () => {
console.log("Readable event triggered");
console.log(
`${new Date().toLocaleString()}, Readable Stream has ${client._socket.readableLength} bytes of data available`
);
if (client._socket.readableLength === 0) {
// for some reason the readable event can trigger but there be nothing in the readable queue
console.log("readable queue is empty");
return;
}
How often does it reproduce? Is there a required condition?
This typically happens when TCP has decided to chunk the return of the data. I read what is available then wait for the next readable event to fire, then I find that the readableLength is zero - despite the readable event having triggered.
What is the expected behavior?
readableLength should contain the number of bytes available in the stream after the readable event has triggered.
What do you see instead?
Readable event triggered
9/17/2021, 7:47:19 AM, Readable Stream has 0 bytes of data available
readable queue is empty
Additional information
No response