diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 3f86262e737a3f..82cbfcc5132f35 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -405,9 +405,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; } } diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 4b7a629cf55fde..44abf29cafb9d9 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.strictEqual(request, req); req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall());