-
Notifications
You must be signed in to change notification settings - Fork 18
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
properly clear completion timeouts #85
Conversation
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.
I think as-is it's misleading and might even throw in strict mode.
@@ -146,6 +146,10 @@ module.exports = Hub = function() { | |||
hub.emit('start', baseLog); | |||
handleResult = function(error, response, body) { | |||
var apiError, logLine, maxStatusCode, minStatusCode, parseError, parseJSON, ref5, ref6, ref7, successfulRequest, uri; | |||
if (responseData.completionSuccessful) { | |||
responseData.completionSuccessful(); | |||
delete responseData.completionSuccessful; |
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.
I don't think this line is doing anything:
const o = Object.defineProperty({}, 'cS', { value: 42 })
// {}
o.cS
// 42
delete o.cS
// false
o.cS
// 42
By default the property isn't writeable or configurable so deleting won't do anything (other than potentially throw in strict mode).
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.
Good to know - wondered, should have checked :-)
lib/hub.js
Outdated
@@ -312,7 +316,9 @@ module.exports = Hub = function() { | |||
clearTimeout(completionTimeout); | |||
return completionTimeout = null; | |||
}; | |||
req.on('complete', completionSuccessful); | |||
Object.defineProperty(responseData, 'completionSuccessful', { |
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.
I think given that this is a function property, it should be okay to just set it. JSON.stringify
and friends will omit it. Alternatively you could use a Symbol to "hide" it.
This makes `keepAlive: true` not terminate the connection after `completionTimeout` ms The code depended on a `complete` event being emitted by `request`, but AFAICT it only does that for non-callback invocations. This explicitly clears it ourselves - `responseData` was the only good place I could see to put the call that didn't require a major refactoring. See: https://github.com/request/request/blob/a6741d415aba31cd01e9c4544c96f84ea6ed11e3/request.js#L1088-L1094
7aea769
to
780c998
Compare
Better? |
This makes
keepAlive: true
not terminate the connection aftercompletionTimeout
msThe code depended on a
complete
event being emitted byrequest
, but AFAICTit only does that for non-callback invocations.
This explicitly clears it ourselves -
responseData
was the only goodplace I could see to put the call that didn't require a major refactoring.
See: https://github.com/request/request/blob/a6741d415aba31cd01e9c4544c96f84ea6ed11e3/request.js#L1088-L1094