-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http2: fix missing 'timeout' event emit in request and response #20918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,7 @@ const kState = Symbol('state'); | |
const kType = Symbol('type'); | ||
const kUpdateTimer = Symbol('update-timer'); | ||
const kWriteGeneric = Symbol('write-generic'); | ||
const kStreamEventsComposite = Symbol('streamEventsComposite'); | ||
|
||
const kDefaultSocketTimeout = 2 * 60 * 1000; | ||
|
||
|
@@ -1551,6 +1552,8 @@ class Http2Stream extends Duplex { | |
trailersReady: false | ||
}; | ||
|
||
this[kStreamEventsComposite] = []; | ||
|
||
this.on('pause', streamOnPause); | ||
} | ||
|
||
|
@@ -1640,7 +1643,17 @@ class Http2Stream extends Duplex { | |
} | ||
} | ||
|
||
this.emit('timeout'); | ||
// if there is no timeout event listener, destroy session | ||
let hasTimeoutCallback = this.emit('timeout'); | ||
for (const component of this[kStreamEventsComposite]) { | ||
if (component.emit('timeout')) { | ||
hasTimeoutCallback = true; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if (!hasTimeoutCallback) { | ||
this.session.destroy(); | ||
} | ||
} | ||
|
||
// true if the HEADERS frame has been sent | ||
|
@@ -2662,7 +2675,8 @@ function setupCompat(ev) { | |
this.on('stream', onServerStream.bind( | ||
this, | ||
this[kOptions].Http2ServerRequest, | ||
this[kOptions].Http2ServerResponse) | ||
this[kOptions].Http2ServerResponse, | ||
kStreamEventsComposite) | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ server.on('request', (req, res) => { | |
req.setTimeout(msecs, common.mustCall(() => { | ||
res.end(); | ||
})); | ||
|
||
res.on('timeout', common.mustCall()); | ||
req.on('timeout', common.mustCall()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add some assertions that verifies that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcollina sure I can. You mean between the |
||
|
||
res.on('finish', common.mustCall(() => { | ||
req.setTimeout(msecs, common.mustNotCall()); | ||
process.nextTick(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding things to an array, I would add an event listener to
'timeout'
on the stream.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina as I described in the 2nd comment here, if we add a
timeout
listener to anEventEmitter
, the checks withif (...emit(...))
will not work, because they all are always true then.