@@ -551,24 +551,31 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
551
551
reverseProxy . incoming . socket . removeListener ( 'data' , listeners . onOutgoing ) ;
552
552
}
553
553
554
- //
554
+ //
555
555
// If the incoming `proxySocket` socket closes, then
556
556
// detach all event listeners.
557
557
//
558
- proxySocket . on ( 'end' , listeners . onIncomingClose = function ( ) {
558
+ listeners . onIncomingClose = function ( ) {
559
+ reverseProxy . incoming . socket . destroy ( ) ;
559
560
detach ( ) ;
560
561
561
562
// 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
+ }
564
565
565
566
//
566
567
// If the `reverseProxy` socket closes, then detach all
567
568
// 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 ) ;
572
579
}
573
580
574
581
function getPort ( port ) {
0 commit comments