@@ -1412,18 +1412,6 @@ function afterDoStreamWrite(status, handle, req) {
1412
1412
req . handle = undefined ;
1413
1413
}
1414
1414
1415
- function onHandleFinish ( ) {
1416
- const handle = this [ kHandle ] ;
1417
- if ( this [ kID ] === undefined ) {
1418
- this . once ( 'ready' , onHandleFinish ) ;
1419
- } else if ( handle !== undefined ) {
1420
- const req = new ShutdownWrap ( ) ;
1421
- req . oncomplete = ( ) => { } ;
1422
- req . handle = handle ;
1423
- handle . shutdown ( req ) ;
1424
- }
1425
- }
1426
-
1427
1415
function streamOnResume ( ) {
1428
1416
if ( ! this . destroyed && ! this . pending )
1429
1417
this [ kHandle ] . readStart ( ) ;
@@ -1444,6 +1432,13 @@ function abort(stream) {
1444
1432
}
1445
1433
}
1446
1434
1435
+ function afterShutdown ( ) {
1436
+ this . callback ( ) ;
1437
+ const stream = this . handle [ kOwner ] ;
1438
+ if ( stream )
1439
+ stream [ kMaybeDestroy ] ( ) ;
1440
+ }
1441
+
1447
1442
// An Http2Stream is a Duplex stream that is backed by a
1448
1443
// node::http2::Http2Stream handle implementing StreamBase.
1449
1444
class Http2Stream extends Duplex {
@@ -1466,7 +1461,6 @@ class Http2Stream extends Duplex {
1466
1461
writeQueueSize : 0
1467
1462
} ;
1468
1463
1469
- this . once ( 'finish' , onHandleFinish ) ;
1470
1464
this . on ( 'resume' , streamOnResume ) ;
1471
1465
this . on ( 'pause' , streamOnPause ) ;
1472
1466
}
@@ -1672,6 +1666,23 @@ class Http2Stream extends Duplex {
1672
1666
trackWriteState ( this , req . bytes ) ;
1673
1667
}
1674
1668
1669
+ _final ( cb ) {
1670
+ const handle = this [ kHandle ] ;
1671
+ if ( this [ kID ] === undefined ) {
1672
+ this . once ( 'ready' , ( ) => this . _final ( cb ) ) ;
1673
+ } else if ( handle !== undefined ) {
1674
+ debug ( `Http2Stream ${ this [ kID ] } [Http2Session ` +
1675
+ `${ sessionName ( this [ kSession ] [ kType ] ) } ]: _final shutting down` ) ;
1676
+ const req = new ShutdownWrap ( ) ;
1677
+ req . oncomplete = afterShutdown ;
1678
+ req . callback = cb ;
1679
+ req . handle = handle ;
1680
+ handle . shutdown ( req ) ;
1681
+ } else {
1682
+ cb ( ) ;
1683
+ }
1684
+ }
1685
+
1675
1686
_read ( nread ) {
1676
1687
if ( this . destroyed ) {
1677
1688
this . push ( null ) ;
0 commit comments