Skip to content

Fix to timeout not being respected#27

Open
pealan wants to merge 3 commits intojohncrisostomo:masterfrom
pealan:master
Open

Fix to timeout not being respected#27
pealan wants to merge 3 commits intojohncrisostomo:masterfrom
pealan:master

Conversation

@pealan
Copy link
Copy Markdown

@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
Copy Markdown

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.

Comment thread index.js Outdated

if (timeout) {
req.setTimeout(timeout, function() {
req.on('timeout', ()=> {
Copy link
Copy Markdown

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
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here

Comment thread index.js Outdated

var options = getOptions(url, port, protocol);

if (timeout)
Copy link
Copy Markdown

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
Copy Markdown
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.

@jp-simons
Copy link
Copy Markdown

Looks good to me.

Comment thread index.js
var options = getOptions(url, port, protocol);

if (timeout) {
options['timeout'] = timeout;
Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread test/index.js
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
Copy Markdown
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
Copy Markdown
Contributor

on pealan:master

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

@DanielRuf
Copy link
Copy Markdown
Contributor

@amtdevops
Copy link
Copy Markdown

@johnnysprinkles could you please merge the latest changes to master

@jp-simons
Copy link
Copy Markdown

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