diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 72d2a83..4a84b58 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -500,8 +500,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) } catch (ex) { detach(); - reverseProxy.incoming.socket.end(); - proxySocket.end(); } } }); @@ -532,8 +530,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) } catch (ex) { detach(); - proxySocket.end(); - socket.end(); } }); @@ -542,8 +538,10 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // from `reverseProxy` and `proxySocket`. // function detach() { + proxySocket.destroySoon(); proxySocket.removeListener('end', listeners.onIncomingClose); proxySocket.removeListener('data', listeners.onIncoming); + reverseProxy.incoming.socket.destroySoon(); reverseProxy.incoming.socket.removeListener('end', listeners.onOutgoingClose); reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing); } @@ -553,7 +551,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // detach all event listeners. // proxySocket.on('end', listeners.onIncomingClose = function() { - reverseProxy.incoming.socket.end(); detach(); // Emit the `end` event now that we have completed proxying @@ -565,7 +562,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // event listeners. // reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose = function() { - proxySocket.end(); detach(); }); }