http2: simplify subsequent rstStream calls

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: https://github.com/nodejs/node/pull/16753
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anatoli Papirovski committed 2017-11-07 12:20:50 -05:00
1 parent daeb7a64a5
commit 795a964006
2 files changed
+6 -3

No files matched your search

+2 -3
View File
@@ -970,9 +970,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;
@@ -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);