Skip to content

Commit

Permalink
fix: send chunked WebSocket frames in a single write (prevent RSV2/3 …
Browse files Browse the repository at this point in the history
…errs) (#150)
  • Loading branch information
rentallect authored Jun 28, 2024
1 parent e82ecb9 commit c6fd38b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/http/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,14 @@ class Sender {
*/
sendFrame(list, cb) {
if (list.length === 2) {
this._socket.write(list[0]);
this._socket.write(list[1], cb);
// The WebSocket frame is in two chunks. Merge the two byte arrays into a single byte array,
// and transmit in a single write (to prevent the receiving side from potentially processing
// a partial frame)
var mergedArray = new Uint8Array(list[0].length + list[1].length);
mergedArray.set(list[0]);
mergedArray.set(list[1], list[0].length);
this._socket.write(mergedArray, cb);

} else {
this._socket.write(list[0], cb);
}
Expand Down

0 comments on commit c6fd38b

Please sign in to comment.