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
  • Loading branch information
jasnell committed Aug 10, 2018
1 parent dcfd323 commit e8f319f
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 @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
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 e8f319f

Please sign in to comment.