File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1464,6 +1464,14 @@ function afterShutdown() {
14641464} 
14651465
14661466function  finishSendTrailers ( stream ,  headersList )  { 
1467+   // The stream might be destroyed and in that case 
1468+   // there is nothing to do. 
1469+   // This can happen because finishSendTrailers is 
1470+   // scheduled via setImmediate. 
1471+   if  ( stream . destroyed )  { 
1472+     return ; 
1473+   } 
1474+ 
14671475  stream [ kState ] . flags  &=  ~ STREAM_FLAGS_HAS_TRAILERS ; 
14681476
14691477  const  ret  =  stream [ kHandle ] . trailers ( headersList ) ; 
Original file line number Diff line number Diff line change 1+ 'use strict' ; 
2+ 
3+ const  common  =  require ( '../common' ) ; 
4+ const  {  mustCall }  =  common ; 
5+ 
6+ if  ( ! common . hasCrypto ) 
7+   common . skip ( 'missing crypto' ) ; 
8+ 
9+ const  http2  =  require ( 'http2' ) ; 
10+ const  assert  =  require ( 'assert' ) ; 
11+ 
12+ const  { 
13+   HTTP2_HEADER_PATH , 
14+   HTTP2_HEADER_METHOD , 
15+ }  =  http2 . constants ; 
16+ 
17+ // This tests verifies that calling `req.socket.destroy()` via 
18+ // setImmediate does not crash. 
19+ // Fixes https://github.com/nodejs/node/issues/22855. 
20+ 
21+ const  app  =  http2 . createServer ( mustCall ( ( req ,  res )  =>  { 
22+   res . end ( 'hello' ) ; 
23+   setImmediate ( ( )  =>  req . socket . destroy ( ) ) ; 
24+ } ) ) ; 
25+ 
26+ app . listen ( 0 ,  mustCall ( ( )  =>  { 
27+   const  session  =  http2 . connect ( `http://localhost:${ app . address ( ) . port }  ) ; 
28+   const  request  =  session . request ( { 
29+     [ HTTP2_HEADER_PATH ] : '/' , 
30+     [ HTTP2_HEADER_METHOD ] : 'get' 
31+   } ) ; 
32+   request . once ( 'response' ,  mustCall ( ( headers ,  flags )  =>  { 
33+     let  data  =  '' ; 
34+     request . on ( 'data' ,  ( chunk )  =>  {  data  +=  chunk ;  } ) ; 
35+     request . on ( 'end' ,  mustCall ( ( )  =>  { 
36+       assert . strictEqual ( data ,  'hello' ) ; 
37+       session . close ( ) ; 
38+       app . close ( ) ; 
39+     } ) ) ; 
40+   } ) ) ; 
41+   request . end ( ) ; 
42+ } ) ) ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments