-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fix to timeout not being respected #27
base: master
Are you sure you want to change the base?
Conversation
index.js
Outdated
|
||
return new Promise(function(resolve, reject) { | ||
var req = handleRequest(options, detailed, resolve, reject); | ||
|
||
if (timeout) { | ||
req.setTimeout(timeout, function() { | ||
req.on('timeout', ()=> { |
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.
Minor style issue: space between the arrow and the parens.
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.
Fixed here
index.js
Outdated
@@ -64,12 +64,15 @@ function get(url, timeout, port, protocol, detailed) { | |||
protocol = protocol || 'https:'; | |||
|
|||
var options = getOptions(url, port, protocol); | |||
|
|||
if (timeout) |
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.
Many JS style guides prohibit if
without a block, always requiring braces even for a single line. How do you feel about that?
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 feel they are right, specially if this standard was used throughout this file. I'll be fixing this and the other style issue.
Looks good to me. |
@@ -64,12 +64,16 @@ function get(url, timeout, port, protocol, detailed) { | |||
protocol = protocol || 'https:'; | |||
|
|||
var options = getOptions(url, port, protocol); | |||
|
|||
if (timeout) { | |||
options['timeout'] = timeout; |
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 would do that with Object.assign
.
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.
Also why not just extend getOptions
?
it('should timeout at expected time', function(done) { | ||
const startTime = new Date(); | ||
getSSLCertificate | ||
.get('59.96.120.246', 1400) // Not sure which unreachable IP to put in here |
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.
Probably any IP controlled by IANA or internal one defined by IANA.
Please create a separate branch instead of using the |
@johnnysprinkles could you please merge the latest changes to master |
I'm not an owner of this library... |
When setting an unreachable IP from your network as the host address, the script fails to return a timeout error at the expected time. I tried to minimally change your script to fix this by using the ClientRequest 'timeout' option when calling 'https.get()'. Also I'm using 'ClientRequest.on('timeout)...' to listen the timeout event. The added test can be used to verify that the error occurs currently. This solution can be improved however, specially the IP used for the test, as someone could have a server running there.