Skip to content

Commit

Permalink
http2: slightly simplify stream destroy
Browse files Browse the repository at this point in the history
PR-URL: #16327
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
apapirovski authored and MylesBorins committed Oct 23, 2017
1 parent 3c41f3f commit bf7c2a3
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,7 @@ class Http2Stream extends Duplex {
}

const server = session[kServer];

if (err && server) {
if (server !== undefined && err) {
server.emit('streamError', err, this);
}

Expand All @@ -1515,10 +1514,10 @@ function continueStreamDestroy(self, err, callback) {

// Submit RST-STREAM frame if one hasn't been sent already and the
// stream hasn't closed normally...
if (!state.rst && !session.destroyed) {
const code =
err instanceof Error ?
NGHTTP2_INTERNAL_ERROR : NGHTTP2_NO_ERROR;
const rst = state.rst;
let code = state.rstCode;
if (!rst && !session.destroyed) {
code = err instanceof Error ? NGHTTP2_INTERNAL_ERROR : NGHTTP2_NO_ERROR;
session.rstStream(self, code);
}

Expand All @@ -1530,13 +1529,10 @@ function continueStreamDestroy(self, err, callback) {

setImmediate(finishStreamDestroy, self, handle);

// All done
const rst = state.rst;
const code = rst ? state.rstCode : NGHTTP2_NO_ERROR;
// RST code 8 not emitted as an error as its used by clients to signify
// abort and is already covered by aborted event, also allows more
// seamless compatibility with http1
if (!err && code !== NGHTTP2_NO_ERROR && code !== NGHTTP2_CANCEL) {
if (code !== NGHTTP2_NO_ERROR && code !== NGHTTP2_CANCEL && !err) {
err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
}
callback(err);
Expand All @@ -1546,8 +1542,7 @@ function continueStreamDestroy(self, err, callback) {

function finishStreamDestroy(self, handle) {
const id = self[kID];
const session = self[kSession];
session[kState].streams.delete(id);
self[kSession][kState].streams.delete(id);
delete self[kSession];
if (handle !== undefined)
handle.destroyStream(id);
Expand Down

0 comments on commit bf7c2a3

Please sign in to comment.