Skip to content

Commit 7feee19

Browse files
committed
[fix] only set one drain listener while paused
1 parent a726965 commit 7feee19

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: lib/node-http-proxy/http-proxy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
224224
// If the res socket has been killed already, then write()
225225
// will throw. Nevertheless, try our best to end it nicely.
226226
//
227+
var paused = false;
227228
response.on('data', function (chunk) {
228229
if (req.method !== 'HEAD' && res.writable) {
229230
try {
@@ -238,9 +239,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
238239
return;
239240
}
240241

241-
if (!flushed) {
242+
if (!flushed && !paused) {
243+
paused = true;
242244
response.pause();
243245
res.once('drain', function () {
246+
paused = false;
244247
try { response.resume() }
245248
catch (er) { console.error("response.resume error: %s", er.message) }
246249
});

0 commit comments

Comments
 (0)