Commit f4fcf934 authored by isaacs's avatar isaacs Committed by indexzero

Memory leak hunting.

Detach listeners and clean up buffer on error
parent 7beead54
......@@ -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();
}
}
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment