Skip to content

Commit c6fd38b

Browse files
authored
fix: send chunked WebSocket frames in a single write (prevent RSV2/3 errs) (#150)
1 parent e82ecb9 commit c6fd38b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/http/sender.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,14 @@ class Sender {
411411
*/
412412
sendFrame(list, cb) {
413413
if (list.length === 2) {
414-
this._socket.write(list[0]);
415-
this._socket.write(list[1], cb);
414+
// The WebSocket frame is in two chunks. Merge the two byte arrays into a single byte array,
415+
// and transmit in a single write (to prevent the receiving side from potentially processing
416+
// a partial frame)
417+
var mergedArray = new Uint8Array(list[0].length + list[1].length);
418+
mergedArray.set(list[0]);
419+
mergedArray.set(list[1], list[0].length);
420+
this._socket.write(mergedArray, cb);
421+
416422
} else {
417423
this._socket.write(list[0], cb);
418424
}

0 commit comments

Comments
 (0)