From 79422fbffc6a927ecc26ace71b2334961af6302b Mon Sep 17 00:00:00 2001 From: Curt Tudor Date: Fri, 28 Jun 2024 09:08:01 -0600 Subject: [PATCH] send chunked WebSocket frames in a single write (prevent RSV2/3 errs) --- src/http/sender.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/http/sender.js b/src/http/sender.js index 3b814b9..fc74f41 100644 --- a/src/http/sender.js +++ b/src/http/sender.js @@ -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); }