From e8f319f5eff682ae67fd203ada03c1f221f4ce99 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 10 Aug 2018 13:33:46 -0700 Subject: [PATCH 1/2] http2: emit timeout on compat request and response Fixes: https://github.com/nodejs/node/issues/20079 --- lib/internal/http2/compat.js | 9 +++++++++ .../test-http2-compat-serverrequest-settimeout.js | 1 + .../test-http2-compat-serverresponse-settimeout.js | 1 + 3 files changed, 11 insertions(+) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 0e9c2832cc7b1f..80ad57e5fa6d52 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -243,6 +243,13 @@ function onStreamCloseRequest() { req.emit('close'); } +function onStreamTimeout(kind) { + return function onStreamTimeout() { + const obj = this[kind]; + obj.emit('timeout'); + } +} + class Http2ServerRequest extends Readable { constructor(stream, headers, options, rawHeaders) { super(options); @@ -265,6 +272,7 @@ class Http2ServerRequest extends Readable { stream.on('error', onStreamError); stream.on('aborted', onStreamAbortedRequest); stream.on('close', onStreamCloseRequest); + stream.on('timeout', onStreamTimeout(kRequest)); this.on('pause', onRequestPause); this.on('resume', onRequestResume); } @@ -418,6 +426,7 @@ class Http2ServerResponse extends Stream { stream.on('aborted', onStreamAbortedResponse); stream.on('close', onStreamCloseResponse); stream.on('wantTrailers', onStreamTrailersReady); + stream.on('timeout', onStreamTimeout(kResponse)); } // User land modules such as finalhandler just check truthiness of this diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 81184d70752563..4b7a629cf55fde 100644 --- a/test/parallel/test-http2-compat-serverrequest-settimeout.js +++ b/test/parallel/test-http2-compat-serverrequest-settimeout.js @@ -12,6 +12,7 @@ server.on('request', (req, res) => { req.setTimeout(msecs, common.mustCall(() => { res.end(); })); + req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall()); process.nextTick(() => { diff --git a/test/parallel/test-http2-compat-serverresponse-settimeout.js b/test/parallel/test-http2-compat-serverresponse-settimeout.js index 220a84a754d651..e24621ad097f3f 100644 --- a/test/parallel/test-http2-compat-serverresponse-settimeout.js +++ b/test/parallel/test-http2-compat-serverresponse-settimeout.js @@ -12,6 +12,7 @@ server.on('request', (req, res) => { res.setTimeout(msecs, common.mustCall(() => { res.end(); })); + res.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { res.setTimeout(msecs, common.mustNotCall()); process.nextTick(() => { From 1f07f0bad43ee78743e92f3bea343d054c45d049 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 10 Aug 2018 14:42:31 -0700 Subject: [PATCH 2/2] [Squash] fix lint --- lib/internal/http2/compat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 80ad57e5fa6d52..4f5a822b6e2f3d 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -247,7 +247,7 @@ function onStreamTimeout(kind) { return function onStreamTimeout() { const obj = this[kind]; obj.emit('timeout'); - } + }; } class Http2ServerRequest extends Readable {