Skip to content

[fix] only set one drain listener while paused #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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