Skip to content

Commit b895ca9

Browse files
addaleaxMylesBorins
authored andcommitted
http2: use _final instead of on('finish')
Backport-PR-URL: #20456 PR-URL: #18609 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
1 parent 0aa7698 commit b895ca9

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
@@ -1412,18 +1412,6 @@ function afterDoStreamWrite(status, handle, req) {
14121412
req.handle = undefined;
14131413
}
14141414

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-
14271415
function streamOnResume() {
14281416
if (!this.destroyed && !this.pending)
14291417
this[kHandle].readStart();
@@ -1444,6 +1432,13 @@ function abort(stream) {
14441432
}
14451433
}
14461434

1435+
function afterShutdown() {
1436+
this.callback();
1437+
const stream = this.handle[kOwner];
1438+
if (stream)
1439+
stream[kMaybeDestroy]();
1440+
}
1441+
14471442
// An Http2Stream is a Duplex stream that is backed by a
14481443
// node::http2::Http2Stream handle implementing StreamBase.
14491444
class Http2Stream extends Duplex {
@@ -1466,7 +1461,6 @@ class Http2Stream extends Duplex {
14661461
writeQueueSize: 0
14671462
};
14681463

1469-
this.once('finish', onHandleFinish);
14701464
this.on('resume', streamOnResume);
14711465
this.on('pause', streamOnPause);
14721466
}
@@ -1672,6 +1666,23 @@ class Http2Stream extends Duplex {
16721666
trackWriteState(this, req.bytes);
16731667
}
16741668

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+
16751686
_read(nread) {
16761687
if (this.destroyed) {
16771688
this.push(null);

0 commit comments

Comments
 (0)