-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
bufferSize of net.Socket sometimes returns double the actual value #34078
Comments
Please write a reproducible test case in JavaScript using only |
|
@BTOdell: Is there are reason why you are not using |
@ronag see discussion on websockets/ws#492 |
Quickly scanned through, seems to be the same issue? |
Yes, it was to answer your question about why @BTOdell was using |
Fixed in 312a4f3 |
What steps will reproduce the bug?
I'm using the WebSocket library
ws
to handle connections from a browser over a VPN. ThebufferedAmount
property ofws
uses thebufferSize
property of the underlying net.Socket object (from the http.createServer function). I've narrowed the bug down to know the incorrect value is only coming from thebufferSize
property in Node.js itself.How often does it reproduce? Is there a required condition?
I'm able to reproduce it reliably in my Linux/Docker environment under certain (slow) network conditions.
This issue seems to happen when the socket is being written to quickly, to the point where write callbacks are getting delayed and batched up (several are called together in quick succession).
What is the expected behavior?
The
bufferSize
should never be greater than the actual number of bytes that were sent to the socket.What do you see instead?
Each time I send a WebSocket packet, I add the length of the packet onto my own 'pending' queue and I remove it from the queue when I receive the send/write callback. After I send the data to the WebSocket, I query the
bufferSize
property and thewritableLength
property of the underlying TCP socket.Using this TS code:
I get this output:
Additional information
I tracked down the code in Node.js that implements the
bufferSize
property: https://github.com/nodejs/node/blob/master/lib/net.js#L544Using the printed value of
writableLength
(56209), that means the value ofthis[kLastWriteQueueSize]
is also 56209. My guess is that one of the values is not getting cleared at the right time. Maybe it's because the Node.js event loop is getting held up by all of the other write requests? I don't know enough about Node.js internals to keep debugging this issue further.The text was updated successfully, but these errors were encountered: