File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2087,6 +2087,12 @@ class Server {
20872087
20882088            if  ( newProxyConfig  !==  proxyConfig )  { 
20892089              proxyConfig  =  newProxyConfig ; 
2090+               const  socket  =  req . socket  !=  null  ? req . socket  : req . connection ; 
2091+               // @ts -ignore 
2092+               const  server  =  socket  !=  null  ? socket . server  : null ; 
2093+               if  ( server )  { 
2094+                 server . removeAllListeners ( "close" ) ; 
2095+               } 
20902096              proxyMiddleware  = 
20912097                /** @type  {RequestHandler } */ 
20922098                ( getProxyMiddleware ( proxyConfig ) ) ; 
Original file line number Diff line number Diff line change @@ -75,9 +75,21 @@ const proxyOption = [
7575  } , 
7676] ; 
7777
78+ let  maxServerListeners  =  0 ; 
7879const  proxyOptionOfArray  =  [ 
7980  {  context : "/proxy1" ,  target : `http://localhost:${ port1 }   } , 
8081  function  proxy ( req ,  res ,  next )  { 
82+     if  ( req  !=  null )  { 
83+       const  socket  =  req . socket  !=  null  ? req . socket  : req . connection ; 
84+       // @ts -ignore 
85+       const  server  =  socket  !=  null  ? socket . server  : null ; 
86+       if  ( server )  { 
87+         maxServerListeners  =  Math . max ( 
88+           maxServerListeners , 
89+           server . listeners ( "close" ) . length 
90+         ) ; 
91+       } 
92+     } 
8193    return  { 
8294      context : "/api/proxy2" , 
8395      target : `http://localhost:${ port2 }  , 
@@ -463,6 +475,10 @@ describe("proxy option", () => {
463475      expect ( response . statusCode ) . toEqual ( 200 ) ; 
464476      expect ( response . text ) . toEqual ( "foo+next+function" ) ; 
465477    } ) ; 
478+ 
479+     it ( "should not exist multiple close events registered" ,  async  ( )  =>  { 
480+       expect ( maxServerListeners ) . toBeLessThanOrEqual ( 1 ) ; 
481+     } ) ; 
466482  } ) ; 
467483
468484  describe ( "as an array without the `route` option" ,  ( )  =>  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments