diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index ed920a2..3d707a0 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -551,10 +551,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { } } if (!flushed) { + //console.error('backpressure 554'); response.pause(); res.once('drain', function () { response.resume(); }); + setTimeout(function () { + res.emit('drain'); + }, 100); } }); @@ -587,10 +591,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { if (!errState) { var flushed = reverseProxy.write(chunk); if (!flushed) { + //console.error('backpressure 594'); req.pause(); reverseProxy.once('drain', function () { req.resume(); }); + setTimeout(function () { + reverseProxy.emit('drain'); + }, 100); } } }); @@ -661,10 +669,14 @@ HttpProxy.prototype._forwardRequest = function (req) { req.on('data', function (chunk) { var flushed = forwardProxy.write(chunk); if (!flushed) { + //console.error('backpressure 672'); req.pause(); forwardProxy.once('drain', function () { req.resume(); }); + setTimeout(function () { + forwardProxy.emit('drain'); + }, 100); } }) @@ -762,10 +774,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options self.emit('websocket:outgoing', req, socket, head, data); var flushed = reverseProxy.incoming.socket.write(data); if (!flushed) { + //console.error('backpressure 777'); proxySocket.pause(); reverseProxy.incoming.socket.once('drain', function () { proxySocket.resume(); }); + setTimeout(function () { + reverseProxy.incoming.socket.emit('drain'); + }, 100); } } catch (e) { @@ -785,10 +801,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options self.emit('websocket:incoming', reverseProxy, reverseProxy.incoming, head, data); var flushed = proxySocket.write(data); if (!flushed) { + //console.error('backpressure 804'); reverseProxy.incoming.socket.pause(); proxySocket.once('drain', function () { reverseProxy.incoming.socket.resume(); }); + setTimeout(function () { + proxySocket.emit('drain'); + }, 100); } } catch (e) { @@ -951,10 +971,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options socket.write(sdata); var flushed = socket.write(data); if (!flushed) { + //console.error('backpressure 974'); reverseProxy.socket.pause(); socket.once('drain', function () { reverseProxy.socket.resume(); }); + setTimeout(function () { + socket.emit('drain'); + }, 100); } }