From 2b25ad1f9a453982fd67b5d5531b5ea79d536772 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sat, 4 Nov 2017 13:42:07 -0400 Subject: [PATCH] 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 Reviewed-By: James M Snell --- lib/internal/http2/core.js | 5 ++--- test/parallel/test-http2-client-rststream-before-connect.js | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index d95e40da6058c1..b719a12fb8a065 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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; diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js index 073b2d4837d2d2..3c4ac3b34d86ad 100644 --- a/test/parallel/test-http2-client-rststream-before-connect.js +++ b/test/parallel/test-http2-client-rststream-before-connect.js @@ -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);