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 authored and Myles Borins committed 2017-12-08 08:54:43 -05:00
1 parent 22ee960775
commit d7f37cebed
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);