From 4a008102a27a00830823884c25e88cf5223af5f8 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 21 Jun 2020 00:49:56 +0530 Subject: [PATCH 1/3] http2: return this for Http2ServerRequest#setTimeout Fixes: https://github.com/nodejs/node/issues/33993 --- lib/internal/http2/compat.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 373311547a3350..4038a4fdb5321d 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -411,9 +411,9 @@ class Http2ServerRequest extends Readable { } setTimeout(msecs, callback) { - if (this[kState].closed) - return; - this[kStream].setTimeout(msecs, callback); + if (!this[kState].closed) + this[kStream].setTimeout(msecs, callback); + return this; } } From c0c116808848e9e38f0eace22062129b1e1f9be2 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 21 Jun 2020 19:11:46 +0530 Subject: [PATCH 2/3] add test --- test/parallel/test-http2-compat-serverrequest-settimeout.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 4b7a629cf55fde..72ae71cb6b9d4a 100644 --- a/test/parallel/test-http2-compat-serverrequest-settimeout.js +++ b/test/parallel/test-http2-compat-serverrequest-settimeout.js @@ -3,15 +3,17 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const http2 = require('http2'); const msecs = common.platformTimeout(1); const server = http2.createServer(); server.on('request', (req, res) => { - req.setTimeout(msecs, common.mustCall(() => { + const request = req.setTimeout(msecs, common.mustCall(() => { res.end(); })); + assert.ok(request instanceof http2.Http2ServerRequest); req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall()); From be5ec87d484da70011d1c278597461533ce194a4 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Mon, 22 Jun 2020 14:56:47 +0530 Subject: [PATCH 3/3] Update test/parallel/test-http2-compat-serverrequest-settimeout.js Co-authored-by: Luigi Pinca --- test/parallel/test-http2-compat-serverrequest-settimeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 72ae71cb6b9d4a..44abf29cafb9d9 100644 --- a/test/parallel/test-http2-compat-serverrequest-settimeout.js +++ b/test/parallel/test-http2-compat-serverrequest-settimeout.js @@ -13,7 +13,7 @@ server.on('request', (req, res) => { const request = req.setTimeout(msecs, common.mustCall(() => { res.end(); })); - assert.ok(request instanceof http2.Http2ServerRequest); + assert.strictEqual(request, req); req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall());