From 810edb81d62aa0fd0cf607663afee5fca7219848 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat Date: Sun, 15 Oct 2017 01:43:00 -0700 Subject: [PATCH] test: http2 rstStream duplicate call This commit fixes an issue with rstStream() which checked incorrect value of rst. It also adds a test case for this fix Refs: https://github.com/nodejs/node/issues/14985 --- lib/internal/http2/core.js | 2 +- .../test-http2-client-rststream-before-connect.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 83db79b950e5c1..586e1f57b35450 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -925,7 +925,7 @@ class Http2Session extends EventEmitter { 'number'); } - if (this[kState].rst) { + if (stream[kState].rst) { // rst has already been called, do not call again, // skip straight to destroy stream.destroy(); diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js index 073b2d4837d2d2..600950dc5c2b3a 100644 --- a/test/parallel/test-http2-client-rststream-before-connect.js +++ b/test/parallel/test-http2-client-rststream-before-connect.js @@ -15,12 +15,15 @@ server.on('listening', common.mustCall(() => { const client = h2.connect(`http://localhost:${server.address().port}`); const req = client.request({ ':path': '/' }); + // make sure that destroy is called twice + req._destroy = common.mustCall(req._destroy.bind(req), 2); + client.rstStream(req, 0); + // redundant call to rstStream with new code + client.rstStream(req, 1); + // confirm that rstCode is from the first call to rstStream assert.strictEqual(req.rstCode, 0); - // make sure that destroy is called - req._destroy = common.mustCall(req._destroy.bind(req)); - req.on('streamClosed', common.mustCall((code) => { assert.strictEqual(req.destroyed, true); assert.strictEqual(code, 0);