From 7feee194f8f9b700c7ea04730ef826272a4f1914 Mon Sep 17 00:00:00 2001 From: bradleymeck Date: Sat, 22 Oct 2011 13:13:10 -0500 Subject: [PATCH] [fix] only set one drain listener while paused --- lib/node-http-proxy/http-proxy.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 204641b09..a3911028f 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -224,6 +224,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { // If the res socket has been killed already, then write() // will throw. Nevertheless, try our best to end it nicely. // + var paused = false; response.on('data', function (chunk) { if (req.method !== 'HEAD' && res.writable) { try { @@ -238,9 +239,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { return; } - if (!flushed) { + if (!flushed && !paused) { + paused = true; response.pause(); res.once('drain', function () { + paused = false; try { response.resume() } catch (er) { console.error("response.resume error: %s", er.message) } });