diff --git a/lib/sender.js b/lib/sender.js index 1ed04b027..da498076f 100644 --- a/lib/sender.js +++ b/lib/sender.js @@ -34,6 +34,13 @@ class Sender { } this._socket = socket; + this._corked = false; + this._uncork = () => { + if (this._corked) { + this._corked = false; + this._socket.uncork(); + } + }; this._firstFragment = true; this._compress = false; @@ -463,11 +470,15 @@ class Sender { * @private */ sendFrame(list, cb) { - if (list.length === 2) { + if (!this._corked) { + this._corked = true; this._socket.cork(); + queueMicrotask(this._uncork); + } + + if (list.length === 2) { this._socket.write(list[0]); this._socket.write(list[1], cb); - this._socket.uncork(); } else { this._socket.write(list[0], cb); }