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

Fix to timeout not being respected #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pealan
Copy link

@pealan pealan commented Oct 29, 2019

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.

@coveralls
Copy link

coveralls commented Oct 29, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 54161b2 on pealan:master into ee1a1fd on johncrisostomo:master.

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', ()=> {

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.

Copy link
Author

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)

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?

Copy link
Author

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.

@johnnysprinkles
Copy link

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;
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

@DanielRuf
Copy link
Contributor

on pealan:master

Please create a separate branch instead of using the masterbranch as this can cause merge conflicts.

@DanielRuf
Copy link
Contributor

@amtdevops
Copy link

@johnnysprinkles could you please merge the latest changes to master

@johnnysprinkles
Copy link

I'm not an owner of this library...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants