Skip to content

Commit 377cfd6

Browse files
addaleaxBridgeAR
authored andcommitted
http2: use _final instead of on('finish')
PR-URL: #18609 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 0cdc877 commit 377cfd6

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/internal/http2/core.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -1415,18 +1415,6 @@ function afterDoStreamWrite(status, handle, req) {
14151415
req.handle = undefined;
14161416
}
14171417

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-
14301418
function streamOnResume() {
14311419
if (!this.destroyed && !this.pending)
14321420
this[kHandle].readStart();
@@ -1447,6 +1435,13 @@ function abort(stream) {
14471435
}
14481436
}
14491437

1438+
function afterShutdown() {
1439+
this.callback();
1440+
const stream = this.handle[kOwner];
1441+
if (stream)
1442+
stream[kMaybeDestroy]();
1443+
}
1444+
14501445
// An Http2Stream is a Duplex stream that is backed by a
14511446
// node::http2::Http2Stream handle implementing StreamBase.
14521447
class Http2Stream extends Duplex {
@@ -1471,7 +1466,6 @@ class Http2Stream extends Duplex {
14711466
writeQueueSize: 0
14721467
};
14731468

1474-
this.once('finish', onHandleFinish);
14751469
this.on('resume', streamOnResume);
14761470
this.on('pause', streamOnPause);
14771471
}
@@ -1678,6 +1672,23 @@ class Http2Stream extends Duplex {
16781672
trackWriteState(this, req.bytes);
16791673
}
16801674

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+
16811692
_read(nread) {
16821693
if (this.destroyed) {
16831694
this.push(null);

0 commit comments

Comments
 (0)