Skip to content

Commit

Permalink
http2: emit timeout on compat request and response
Browse files Browse the repository at this point in the history
Fixes: #20079

PR-URL: #22252
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
jasnell authored and targos committed Sep 3, 2018
1 parent 3f93782 commit d3ceaa1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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);
Expand All @@ -263,6 +270,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);
}
Expand Down Expand Up @@ -416,6 +424,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit d3ceaa1

Please sign in to comment.