-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Proxy requests are closed when server response already sent #906
Changes from 1 commit
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 |
---|---|---|
|
@@ -22,6 +22,8 @@ exports.request = function (method, url, options, callback, _trace) { | |
// Setup request | ||
|
||
var uri = Url.parse(url); | ||
var timeoutId; | ||
var finishListener; | ||
uri.method = method.toUpperCase(); | ||
uri.headers = options.headers; | ||
|
||
|
@@ -49,6 +51,11 @@ exports.request = function (method, url, options, callback, _trace) { | |
|
||
req.removeAllListeners(); | ||
req.on('error', Utils.ignore); | ||
clearTimeout(timeoutId); | ||
|
||
if (options.response && finishListener) { | ||
options.response.removeListener('finish', finishListener); | ||
} | ||
|
||
return callback(err, res); | ||
} | ||
|
@@ -122,11 +129,21 @@ exports.request = function (method, url, options, callback, _trace) { | |
} | ||
|
||
if (options.timeout) { | ||
req.setTimeout(options.timeout, function () { | ||
timeoutId = setTimeout(function () { | ||
|
||
req.destroy(); | ||
req.setTimeout(0); | ||
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. What is this for? 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. It will remove any socket timeout listeners (https://github.com/joyent/node/blob/v0.10.9-release/lib/net.js#L315). |
||
return finish(Boom.internal('Client request timeout')); | ||
}); | ||
}, options.timeout); | ||
} | ||
|
||
if (options.response) { | ||
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. call is |
||
finishListener = function () { | ||
|
||
req.abort(); | ||
return finish(Boom.internal('Server response finished before client response')); | ||
}; | ||
|
||
options.response.once('finish', finishListener); | ||
} | ||
|
||
// Finalize request | ||
|
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.
you don't need this since request._reply will clean it up.