From 43e5f3332081d3e9e61e3436eb99f7df8ca515c9 Mon Sep 17 00:00:00 2001 From: Giannis Dzegoutanis Date: Sun, 10 Feb 2013 23:07:40 +0100 Subject: [PATCH 1/2] fixed issue #364 'proxyError' event emitted twice --- lib/node-http-proxy/http-proxy.js | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index e23d551..8ff7a36 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -312,9 +312,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { // Handle 'error' events from the `reverseProxy`. // reverseProxy.once('error', proxyError); - reverseProxy.once('socket', function (socket) { - socket.once('error', proxyError); - }); + // + // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' + // Look for socketErrorListener references in + // https://github.com/joyent/node/blob/master/lib/http.js + // + // reverseProxy.once('socket', function (socket) { + // socket.once('error', proxyError); + // }); // // Handle 'error' events from the `req` (e.g. `Parse Error`). @@ -719,8 +724,13 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) return proxyError(ex); } + // + // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' + // Look for socketErrorListener references in + // https://github.com/joyent/node/blob/master/lib/http.js + // // Catch socket errors - socket.on('error', proxyError); + //socket.on('error', proxyError); // // Remove data listener now that the 'handshake' is complete @@ -729,10 +739,18 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) }); }); + // + // Handle 'error' events from the `reverseProxy`. + // reverseProxy.on('error', proxyError); - reverseProxy.once('socket', function (socket) { - socket.once('error', proxyError); - }); + // + // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' + // Look for socketErrorListener references in + // https://github.com/joyent/node/blob/master/lib/http.js + // + // reverseProxy.once('socket', function (socket) { + // socket.once('error', proxyError); + // }); // // Handle 'error' events from the `req` (e.g. `Parse Error`). From 3b84e27ab4efd5ce3b8ac837d699d4ff6661c7e7 Mon Sep 17 00:00:00 2001 From: Giannis Dzegoutanis Date: Tue, 12 Feb 2013 20:43:22 +0100 Subject: [PATCH 2/2] remove offending code, final fix for issue #364 --- lib/node-http-proxy/http-proxy.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 8ff7a36..bed0202 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -312,14 +312,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { // Handle 'error' events from the `reverseProxy`. // reverseProxy.once('error', proxyError); - // - // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' - // Look for socketErrorListener references in - // https://github.com/joyent/node/blob/master/lib/http.js - // - // reverseProxy.once('socket', function (socket) { - // socket.once('error', proxyError); - // }); // // Handle 'error' events from the `req` (e.g. `Parse Error`). @@ -724,14 +716,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) return proxyError(ex); } - // - // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' - // Look for socketErrorListener references in - // https://github.com/joyent/node/blob/master/lib/http.js - // - // Catch socket errors - //socket.on('error', proxyError); - // // Remove data listener now that the 'handshake' is complete // @@ -743,14 +727,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // Handle 'error' events from the `reverseProxy`. // reverseProxy.on('error', proxyError); - // - // NOT needed as node.js re-emits the socket errors as ClientRequest 'error' - // Look for socketErrorListener references in - // https://github.com/joyent/node/blob/master/lib/http.js - // - // reverseProxy.once('socket', function (socket) { - // socket.once('error', proxyError); - // }); // // Handle 'error' events from the `req` (e.g. `Parse Error`).