Skip to content

Commit

Permalink
Merge pull request #136 from bmeck/drain-fix
Browse files Browse the repository at this point in the history
[fix] only set one drain listener while paused
  • Loading branch information
indexzero committed Oct 22, 2011
2 parents a726965 + 7feee19 commit cdb4524
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) }
});
Expand Down

0 comments on commit cdb4524

Please sign in to comment.