Skip to content

Commit 43e5f33

Browse files
committed
fixed issue http-party#364 'proxyError' event emitted twice
1 parent 26d3646 commit 43e5f33

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

lib/node-http-proxy/http-proxy.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
312312
// Handle 'error' events from the `reverseProxy`.
313313
//
314314
reverseProxy.once('error', proxyError);
315-
reverseProxy.once('socket', function (socket) {
316-
socket.once('error', proxyError);
317-
});
315+
//
316+
// NOT needed as node.js re-emits the socket errors as ClientRequest 'error'
317+
// Look for socketErrorListener references in
318+
// https://github.com/joyent/node/blob/master/lib/http.js
319+
//
320+
// reverseProxy.once('socket', function (socket) {
321+
// socket.once('error', proxyError);
322+
// });
318323

319324
//
320325
// Handle 'error' events from the `req` (e.g. `Parse Error`).
@@ -719,8 +724,13 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
719724
return proxyError(ex);
720725
}
721726

727+
//
728+
// NOT needed as node.js re-emits the socket errors as ClientRequest 'error'
729+
// Look for socketErrorListener references in
730+
// https://github.com/joyent/node/blob/master/lib/http.js
731+
//
722732
// Catch socket errors
723-
socket.on('error', proxyError);
733+
//socket.on('error', proxyError);
724734

725735
//
726736
// Remove data listener now that the 'handshake' is complete
@@ -729,10 +739,18 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
729739
});
730740
});
731741

742+
//
743+
// Handle 'error' events from the `reverseProxy`.
744+
//
732745
reverseProxy.on('error', proxyError);
733-
reverseProxy.once('socket', function (socket) {
734-
socket.once('error', proxyError);
735-
});
746+
//
747+
// NOT needed as node.js re-emits the socket errors as ClientRequest 'error'
748+
// Look for socketErrorListener references in
749+
// https://github.com/joyent/node/blob/master/lib/http.js
750+
//
751+
// reverseProxy.once('socket', function (socket) {
752+
// socket.once('error', proxyError);
753+
// });
736754

737755
//
738756
// Handle 'error' events from the `req` (e.g. `Parse Error`).

0 commit comments

Comments
 (0)