Skip to content

Commit

Permalink
http2: simplify subsequent rstStream calls
Browse files Browse the repository at this point in the history
Do not call destroy each time rstStream is called since the
first call (or receipt of rst frame) will always trigger
destroy. Expand existing test for this behaviour.

PR-URL: #16753
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
apapirovski authored and MylesBorins committed Dec 7, 2017
1 parent ba12784 commit 2b25ad1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,8 @@ class Http2Session extends EventEmitter {

const state = stream[kState];
if (state.rst) {
// rst has already been called, do not call again,
// skip straight to destroy
stream.destroy();
// rst has already been called by self or peer,
// do not call again
return;
}
state.rst = true;
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http2-client-rststream-before-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ server.on('listening', common.mustCall(() => {
// make sure that destroy is called
req._destroy = common.mustCall(req._destroy.bind(req));

// second call doesn't do anything
assert.doesNotThrow(() => client.rstStream(req, 8));
assert.strictEqual(req.rstCode, 0);

req.on('streamClosed', common.mustCall((code) => {
assert.strictEqual(req.destroyed, true);
assert.strictEqual(code, 0);
Expand Down

0 comments on commit 2b25ad1

Please sign in to comment.