Skip to content

Commit

Permalink
http2: use _final instead of on('finish')
Browse files Browse the repository at this point in the history
Backport-PR-URL: #20456
PR-URL: #18609
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed May 15, 2018
1 parent 39267e8 commit 20fb59f
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1409,18 +1409,6 @@ function afterDoStreamWrite(status, handle, req) {
req.handle = undefined;
}

function onHandleFinish() {
const handle = this[kHandle];
if (this[kID] === undefined) {
this.once('ready', onHandleFinish);
} else if (handle !== undefined) {
const req = new ShutdownWrap();
req.oncomplete = () => {};
req.handle = handle;
handle.shutdown(req);
}
}

function streamOnResume() {
if (!this.destroyed && !this.pending)
this[kHandle].readStart();
Expand All @@ -1441,6 +1429,13 @@ function abort(stream) {
}
}

function afterShutdown() {
this.callback();
const stream = this.handle[kOwner];
if (stream)
stream[kMaybeDestroy]();
}

// An Http2Stream is a Duplex stream that is backed by a
// node::http2::Http2Stream handle implementing StreamBase.
class Http2Stream extends Duplex {
Expand All @@ -1463,7 +1458,6 @@ class Http2Stream extends Duplex {
writeQueueSize: 0
};

this.once('finish', onHandleFinish);
this.on('resume', streamOnResume);
this.on('pause', streamOnPause);
}
Expand Down Expand Up @@ -1669,6 +1663,23 @@ class Http2Stream extends Duplex {
trackWriteState(this, req.bytes);
}

_final(cb) {
const handle = this[kHandle];
if (this[kID] === undefined) {
this.once('ready', () => this._final(cb));
} else if (handle !== undefined) {
debug(`Http2Stream ${this[kID]} [Http2Session ` +
`${sessionName(this[kSession][kType])}]: _final shutting down`);
const req = new ShutdownWrap();
req.oncomplete = afterShutdown;
req.callback = cb;
req.handle = handle;
handle.shutdown(req);
} else {
cb();
}
}

_read(nread) {
if (this.destroyed) {
this.push(null);
Expand Down

0 comments on commit 20fb59f

Please sign in to comment.