Skip to content
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

Merged
merged 1 commit into from
Jun 7, 2018

Conversation

dbushong
Copy link
Member

@dbushong dbushong commented Jun 7, 2018

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

Copy link
Collaborator

@jkrems jkrems left a 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;
Copy link
Collaborator

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).

Copy link
Member Author

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', {
Copy link
Collaborator

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
@dbushong dbushong force-pushed the dbushong/feature/2.x/fix-completion-timeout branch from 7aea769 to 780c998 Compare June 7, 2018 16:01
@dbushong
Copy link
Member Author

dbushong commented Jun 7, 2018

Better?

@dbushong dbushong merged commit 164c6b6 into 2.x Jun 7, 2018
@dbushong dbushong deleted the dbushong/feature/2.x/fix-completion-timeout branch June 7, 2018 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants