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