Skip to content

Commit a162942

Browse files
committed
[fix] Use socket._writableState.length instead of socket.bufferSize
Refs: nodejs/node#34088
1 parent 41b0f9b commit a162942

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/websocket.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ class WebSocket extends EventEmitter {
116116
get bufferedAmount() {
117117
if (!this._socket) return this._bufferedAmount;
118118

119-
//
120-
// `socket.bufferSize` is `undefined` if the socket is closed.
121-
//
122-
return (this._socket.bufferSize || 0) + this._sender._bufferedBytes;
119+
return this._socket._writableState.length + this._sender._bufferedBytes;
123120
}
124121

125122
/**

test/websocket.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,15 @@ describe('WebSocket', () => {
208208
wss.on('connection', (ws) => {
209209
const data = Buffer.alloc(1024, 61);
210210

211-
while (ws._socket.bufferSize === 0) {
211+
while (ws.bufferedAmount === 0) {
212212
ws.send(data);
213213
}
214214

215-
assert.ok(ws._socket.bufferSize > 0);
216-
assert.strictEqual(ws.bufferedAmount, ws._socket.bufferSize);
215+
assert.ok(ws.bufferedAmount > 0);
216+
assert.strictEqual(
217+
ws.bufferedAmount,
218+
ws._socket._writableState.length
219+
);
217220

218221
ws.on('close', () => wss.close(done));
219222
ws.close();

0 commit comments

Comments
 (0)