Skip to content

Commit 1998485

Browse files
committed
[fix] Ensure all remaining data is read as a single chunk
Do not rely on undocumented behavior, call `socket.read()` with the actual number of bytes to read. Refs: nodejs/node#60441
1 parent 726c373 commit 1998485

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/websocket.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,23 +1308,23 @@ function socketOnClose() {
13081308

13091309
websocket._readyState = WebSocket.CLOSING;
13101310

1311-
let chunk;
1312-
13131311
//
13141312
// The close frame might not have been received or the `'end'` event emitted,
13151313
// for example, if the socket was destroyed due to an error. Ensure that the
13161314
// `receiver` stream is closed after writing any remaining buffered data to
13171315
// it. If the readable side of the socket is in flowing mode then there is no
1318-
// buffered data as everything has been already written and `readable.read()`
1319-
// will return `null`. If instead, the socket is paused, any possible buffered
1320-
// data will be read as a single chunk.
1316+
// buffered data as everything has been already written. If instead, the
1317+
// socket is paused, any possible buffered data will be read as a single
1318+
// chunk.
13211319
//
13221320
if (
13231321
!this._readableState.endEmitted &&
13241322
!websocket._closeFrameReceived &&
13251323
!websocket._receiver._writableState.errorEmitted &&
1326-
(chunk = websocket._socket.read()) !== null
1324+
this._readableState.length !== 0
13271325
) {
1326+
const chunk = this.read(this._readableState.length);
1327+
13281328
websocket._receiver.write(chunk);
13291329
}
13301330

0 commit comments

Comments
 (0)