@@ -1460,27 +1460,7 @@ class Http2Session extends EventEmitter {
14601460 }
14611461
14621462 _onTimeout ( ) {
1463- // If the session is destroyed, this should never actually be invoked,
1464- // but just in case...
1465- if ( this . destroyed )
1466- return ;
1467- // This checks whether a write is currently in progress and also whether
1468- // that write is actually sending data across the write. The kHandle
1469- // stored `chunksSentSinceLastWrite` is only updated when a timeout event
1470- // happens, meaning that if a write is ongoing it should never equal the
1471- // newly fetched, updated value.
1472- if ( this [ kState ] . writeQueueSize > 0 ) {
1473- const handle = this [ kHandle ] ;
1474- const chunksSentSinceLastWrite = handle !== undefined ?
1475- handle . chunksSentSinceLastWrite : null ;
1476- if ( chunksSentSinceLastWrite !== null &&
1477- chunksSentSinceLastWrite !== handle . updateChunksSent ( ) ) {
1478- this [ kUpdateTimer ] ( ) ;
1479- return ;
1480- }
1481- }
1482-
1483- this . emit ( 'timeout' ) ;
1463+ callTimeout ( this ) ;
14841464 }
14851465
14861466 ref ( ) {
@@ -1909,25 +1889,7 @@ class Http2Stream extends Duplex {
19091889 }
19101890
19111891 _onTimeout ( ) {
1912- if ( this . destroyed )
1913- return ;
1914- // This checks whether a write is currently in progress and also whether
1915- // that write is actually sending data across the write. The kHandle
1916- // stored `chunksSentSinceLastWrite` is only updated when a timeout event
1917- // happens, meaning that if a write is ongoing it should never equal the
1918- // newly fetched, updated value.
1919- if ( this [ kState ] . writeQueueSize > 0 ) {
1920- const handle = this [ kSession ] [ kHandle ] ;
1921- const chunksSentSinceLastWrite = handle !== undefined ?
1922- handle . chunksSentSinceLastWrite : null ;
1923- if ( chunksSentSinceLastWrite !== null &&
1924- chunksSentSinceLastWrite !== handle . updateChunksSent ( ) ) {
1925- this [ kUpdateTimer ] ( ) ;
1926- return ;
1927- }
1928- }
1929-
1930- this . emit ( 'timeout' ) ;
1892+ callTimeout ( this , kSession ) ;
19311893 }
19321894
19331895 // True if the HEADERS frame has been sent
@@ -2214,6 +2176,30 @@ class Http2Stream extends Duplex {
22142176 }
22152177}
22162178
2179+ function callTimeout ( self , kSession ) {
2180+ // If the session is destroyed, this should never actually be invoked,
2181+ // but just in case...
2182+ if ( self . destroyed )
2183+ return ;
2184+ // This checks whether a write is currently in progress and also whether
2185+ // that write is actually sending data across the write. The kHandle
2186+ // stored `chunksSentSinceLastWrite` is only updated when a timeout event
2187+ // happens, meaning that if a write is ongoing it should never equal the
2188+ // newly fetched, updated value.
2189+ if ( self [ kState ] . writeQueueSize > 0 ) {
2190+ const handle = kSession ? self [ kSession ] [ kHandle ] : self [ kHandle ] ;
2191+ const chunksSentSinceLastWrite = handle !== undefined ?
2192+ handle . chunksSentSinceLastWrite : null ;
2193+ if ( chunksSentSinceLastWrite !== null &&
2194+ chunksSentSinceLastWrite !== handle . updateChunksSent ( ) ) {
2195+ self [ kUpdateTimer ] ( ) ;
2196+ return ;
2197+ }
2198+ }
2199+
2200+ self . emit ( 'timeout' ) ;
2201+ }
2202+
22172203function callStreamClose ( stream ) {
22182204 stream . close ( ) ;
22192205}
0 commit comments