mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Memory leak hunting.
Detach listeners and clean up buffer on error
This commit is contained in:
parent
7beead5465
commit
f4fcf93403
@ -344,6 +344,13 @@ HttpProxy.prototype.buffer = function (obj) {
|
||||
obj.removeListener('data', onData);
|
||||
obj.removeListener('end', onEnd);
|
||||
},
|
||||
destroy: function () {
|
||||
this.end();
|
||||
this.resume = function () {
|
||||
console.error("Cannot resume buffer after destroying it.");
|
||||
};
|
||||
onData = onEnd = events = obj = null;
|
||||
},
|
||||
resume: function () {
|
||||
this.end();
|
||||
for (var i = 0, len = events.length; i < len; ++i) {
|
||||
@ -586,8 +593,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
});
|
||||
|
||||
// If we have been passed buffered data, resume it.
|
||||
if (options.buffer && !errState) {
|
||||
options.buffer.resume();
|
||||
if (options.buffer) {
|
||||
if (!errState) {
|
||||
options.buffer.resume();
|
||||
} else {
|
||||
options.buffer.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -733,6 +744,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
|
||||
reverseProxy.incoming.socket.write(data);
|
||||
}
|
||||
catch (e) {
|
||||
detach();
|
||||
reverseProxy.incoming.socket.end();
|
||||
proxySocket.end();
|
||||
}
|
||||
@ -749,6 +761,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
|
||||
proxySocket.write(data);
|
||||
}
|
||||
catch (e) {
|
||||
detach();
|
||||
proxySocket.end();
|
||||
socket.end();
|
||||
}
|
||||
@ -833,7 +846,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
|
||||
if (self.emit('webSocketProxyError', req, socket, head)) {
|
||||
return;
|
||||
}
|
||||
|
||||
socket.end();
|
||||
}
|
||||
|
||||
@ -932,10 +944,12 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
|
||||
proxyError(ex);
|
||||
}
|
||||
|
||||
//
|
||||
// If we have been passed buffered data, resume it.
|
||||
//
|
||||
if (options.buffer && !errState) {
|
||||
options.buffer.resume();
|
||||
if (options.buffer) {
|
||||
if (!errState) {
|
||||
options.buffer.resume();
|
||||
} else {
|
||||
options.buffer.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user