Skip to content

Commit 84be9f2

Browse files
isaacsindexzero
authored andcommitted
Emit drain if it doesn't happen on its own in 100ms
1 parent 2b9e09b commit 84be9f2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/node-http-proxy.js

+24
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
551551
}
552552
}
553553
if (!flushed) {
554+
//console.error('backpressure 554');
554555
response.pause();
555556
res.once('drain', function () {
556557
response.resume();
557558
});
559+
setTimeout(function () {
560+
res.emit('drain');
561+
}, 100);
558562
}
559563
});
560564

@@ -587,10 +591,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
587591
if (!errState) {
588592
var flushed = reverseProxy.write(chunk);
589593
if (!flushed) {
594+
//console.error('backpressure 594');
590595
req.pause();
591596
reverseProxy.once('drain', function () {
592597
req.resume();
593598
});
599+
setTimeout(function () {
600+
reverseProxy.emit('drain');
601+
}, 100);
594602
}
595603
}
596604
});
@@ -661,10 +669,14 @@ HttpProxy.prototype._forwardRequest = function (req) {
661669
req.on('data', function (chunk) {
662670
var flushed = forwardProxy.write(chunk);
663671
if (!flushed) {
672+
//console.error('backpressure 672');
664673
req.pause();
665674
forwardProxy.once('drain', function () {
666675
req.resume();
667676
});
677+
setTimeout(function () {
678+
forwardProxy.emit('drain');
679+
}, 100);
668680
}
669681
})
670682

@@ -762,10 +774,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
762774
self.emit('websocket:outgoing', req, socket, head, data);
763775
var flushed = reverseProxy.incoming.socket.write(data);
764776
if (!flushed) {
777+
//console.error('backpressure 777');
765778
proxySocket.pause();
766779
reverseProxy.incoming.socket.once('drain', function () {
767780
proxySocket.resume();
768781
});
782+
setTimeout(function () {
783+
reverseProxy.incoming.socket.emit('drain');
784+
}, 100);
769785
}
770786
}
771787
catch (e) {
@@ -785,10 +801,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
785801
self.emit('websocket:incoming', reverseProxy, reverseProxy.incoming, head, data);
786802
var flushed = proxySocket.write(data);
787803
if (!flushed) {
804+
//console.error('backpressure 804');
788805
reverseProxy.incoming.socket.pause();
789806
proxySocket.once('drain', function () {
790807
reverseProxy.incoming.socket.resume();
791808
});
809+
setTimeout(function () {
810+
proxySocket.emit('drain');
811+
}, 100);
792812
}
793813
}
794814
catch (e) {
@@ -951,10 +971,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
951971
socket.write(sdata);
952972
var flushed = socket.write(data);
953973
if (!flushed) {
974+
//console.error('backpressure 974');
954975
reverseProxy.socket.pause();
955976
socket.once('drain', function () {
956977
reverseProxy.socket.resume();
957978
});
979+
setTimeout(function () {
980+
socket.emit('drain');
981+
}, 100);
958982
}
959983

960984
}

0 commit comments

Comments
 (0)