ws: `bufferedAmount` property is broken
The bufferedAmount property doesn’t work correctly.
This code:
var WebSocket = require('ws')
var socket = new WebSocket('wss://echo.websocket.org')
socket.onopen = function () {
socket.send('abc')
console.log('bufferedAmount after send: ' + socket.bufferedAmount)
}
socket.onmessage = function () {
console.log('bufferedAmount after onmessage: ' + socket.bufferedAmount)
}
setInterval(function () {
console.log('bufferedAmount on interval: ' + socket.bufferedAmount)
}, 1000)
Prints:
bufferedAmount after send: 10
bufferedAmount after onmessage: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
bufferedAmount on interval: 1
...
In Chrome and Firefox, on the other hand, this is what gets output:
bufferedAmount after send: 3
bufferedAmount after onmessage: 0
bufferedAmount on interval: 0
bufferedAmount on interval: 0
bufferedAmount on interval: 0
bufferedAmount on interval: 0
bufferedAmount on interval: 0
bufferedAmount on interval: 0
...
Without a functioning bufferedAmount property, it’s not possible to use the code I’ve written to implement backpressure in the browser on the server as well.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 27 (11 by maintainers)
Commits related to this issue
- add backpressure support Fixes https://github.com/feross/simple-websocket/issues/4 No backpressure in node. The `ws` module has a buggy `bufferedAmount` property. See: https://github.com/websockets/... — committed to feross/simple-websocket by feross 9 years ago
- [doc] Improve documentation for `websocket.bufferedAmount` Closes #492 — committed to crsgit/ws by lpinca 4 years ago
If I understand the issue correctly,
bufferedAmountwas reporting +1 size even on an empty buffer. This was a fixed in node v8.8.0 (issue #15005)If that was the issue, then yes,
bufferedAmountis correctly reporting zero now after theonmessage. Although, I am still at a loss as to why it took 10 bytes (18 as of v10.8.0) to contain 3 ascii characters. I would love to find out if anyone knows.