Skip to content

Commit 24b8406

Browse files
piscisaureusmmalecki
authored andcommitted
Fix socket leaks when FIN packet isn't responded to
1 parent 0d00b06 commit 24b8406

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
500500
}
501501
catch (ex) {
502502
detach();
503-
reverseProxy.incoming.socket.end();
504-
proxySocket.end();
505503
}
506504
}
507505
});
@@ -532,8 +530,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
532530
}
533531
catch (ex) {
534532
detach();
535-
proxySocket.end();
536-
socket.end();
537533
}
538534
});
539535

@@ -542,8 +538,10 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
542538
// from `reverseProxy` and `proxySocket`.
543539
//
544540
function detach() {
541+
proxySocket.destroySoon();
545542
proxySocket.removeListener('end', listeners.onIncomingClose);
546543
proxySocket.removeListener('data', listeners.onIncoming);
544+
reverseProxy.incoming.socket.destroySoon();
547545
reverseProxy.incoming.socket.removeListener('end', listeners.onOutgoingClose);
548546
reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing);
549547
}
@@ -553,7 +551,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
553551
// detach all event listeners.
554552
//
555553
proxySocket.on('end', listeners.onIncomingClose = function() {
556-
reverseProxy.incoming.socket.end();
557554
detach();
558555

559556
// Emit the `end` event now that we have completed proxying
@@ -565,7 +562,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
565562
// event listeners.
566563
//
567564
reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose = function() {
568-
proxySocket.end();
569565
detach();
570566
});
571567
}

0 commit comments

Comments
 (0)