Skip to content

Commit 2055d0c

Browse files
unknownindexzero
unknown
authored andcommitted
memory leak fix in closing of the scokets
1 parent 013cb2e commit 2055d0c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -551,24 +551,31 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
551551
reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing);
552552
}
553553

554-
//
554+
//
555555
// If the incoming `proxySocket` socket closes, then
556556
// detach all event listeners.
557557
//
558-
proxySocket.on('end', listeners.onIncomingClose = function() {
558+
listeners.onIncomingClose = function() {
559+
reverseProxy.incoming.socket.destroy();
559560
detach();
560561

561562
// Emit the `end` event now that we have completed proxying
562-
self.emit('websocket:end', req, socket, head);
563-
});
563+
self.emit('websocket:end', req, socket, head);
564+
}
564565

565566
//
566567
// If the `reverseProxy` socket closes, then detach all
567568
// event listeners.
568-
//
569-
reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose = function() {
570-
detach();
571-
});
569+
//
570+
listeners.onOutgoingClose = function() {
571+
proxySocket.destroy();
572+
detach();
573+
}
574+
575+
proxySocket.on('end', listeners.onIncomingClose);
576+
proxySocket.on('close', listeners.onIncomingClose);
577+
reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose);
578+
reverseProxy.incoming.socket.on('close', listeners.onOutgoingClose);
572579
}
573580

574581
function getPort (port) {

0 commit comments

Comments
 (0)