GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dns - add 'all' option to dns.lookup by silverwind · Pull Request #744 · nodejs/node

Conversation

@silverwind

@silverwind silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

Issue: #736

Open questions:

  • Should dns.lookup(null, {all: true}) return an empty array (returns null right now)?
  • I assume c-ares can't return mixed 4/6 results, as the callback just gets addresses. Correct?
  • Test: Is it possible to reliably test the !this.family code path?

/cc @bnoordhuis

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread lib/dns.js Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

Can you do this with a for loop instead of map() for performance reasons.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

Sure, if the difference is worthwile.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Feb 6, 2015

Copy link
Copy Markdown
Member

Should dns.lookup(null, {all: true}) return an empty array (returns null right now) ?

That seems reasonable.

I assume C-Ares can't return mixed 4/6 results, as the callback just gets addresses. Correct?

Wrong. :-)

The logic is in AfterGetAddrInfo() in src/cares_wrap.cc and probably needs to be adjusted in this PR. In a nutshell, you can tell c-ares to query for IPv4 and IPv6 by setting the address family to AF_UNSPEC (family=0 in JS.)

Test: Is it possible to reliably test the !this.family code path?

Not easily, I think.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Feb 6, 2015
View reviewed changes
Comment thread lib/dns.js Outdated

@bnoordhuis bnoordhuis Feb 6, 2015

Copy link
Copy Markdown
Member

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.

addr.includes(':')?

EDIT: Never mind, just noticed that onlookup() does the same.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vkurchatkin vkurchatkin Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

#327

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

@bnoordhuis why does the C++ logic need to change? It's returning the correct array based on the desired family. The JS logic is just giving all the results back instead of the first result.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Feb 6, 2015

Copy link
Copy Markdown
Member

@cjihrig Please disregard that remark. I wrote that before I realized that lib/dns.js already does an ersatz IPv6 check.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread test/internet/test-dns.js Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

Can you add a test that doesn't specify the family and check for mixed results.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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 mean fail the test if mixed results are obtained?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

No. If you don't specify the family, you should be able to get all IPv4 and IPv6 addresses.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

Ah, I see what you mean:

> require("dns").lookup("www.google.com", {all: true}, console.log)
null [ { address: '188.21.9.123', family: 4 },
  { address: '188.21.9.117', family: 4 },
  { address: '188.21.9.121', family: 4 },
  { address: '188.21.9.122', family: 4 },
  { address: '188.21.9.118', family: 4 },
  { address: '188.21.9.119', family: 4 },
  { address: '188.21.9.116', family: 4 },
  { address: '188.21.9.120', family: 4 },
  { address: '2a00:1450:4014:80a::1010', family: 6 } ]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@silverwind

silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

So, no change need there? I see that family = 0 can reach cares.getaddrinfo.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread doc/api/dns.markdown Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

Can you add Defaults to false.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

This describes how the callback arguments are changed, but doesn't really describe the purpose of all. Can you add something like "Return all matching addresses when true"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Feb 6, 2015

Copy link
Copy Markdown
Member

So, no change need there? I see that family = 0 can reach cares.getaddrinfo.

Yep, it's fine.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

Mixed test done. Had to fight a few other test failing, but both appear to be because of my specific dns setup. Just to note, the failing tests on OS X were:

  • test_resolve_failure: returned ENODATA instead of ENOTFOUND / ESERVFAIL
  • test_reverse_failure: my router did reverse-resolve 0.0.0.0 because I have intercepting adblocking through DNS in place.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread doc/api/dns.markdown Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

This should go before the With the all option set,... sentence.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

The whole paragraph?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

Yes. I think it's helpful to define the default behavior before going into what it means for all to be set.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@silverwind

silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

All done. I restructured the docs to make more sense in the last commit.

Let me know when to squash, as I'd like to fix the commit message.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread lib/dns.js Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

Tiny style nit, but can you put the var here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

Sure. Generally, I try to put var at the start of the scope, but i guess I'll follow the style of that file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

There is one case that hasn't been covered - https://github.com/iojs/io.js/blob/v1.x/lib/dns.js#L130. Other than that, and the style nit, LGTM. You can squash, the commits and follow the instructions in https://github.com/iojs/io.js/blob/v1.x/CONTRIBUTING.md#step-3-commit

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

@cjihrig honored your last suggestions and also added two more tests. do these look good to you so I can squash?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Feb 6, 2015
View reviewed changes
Comment thread test/internet/test-dns.js Outdated

@cjihrig cjihrig Feb 6, 2015

Copy link
Copy Markdown
Contributor

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.

It doesn't matter a ton since this is a test, but I think you'd want to check for Array.isArray(ips) before checking the ips.length.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

Right, I'll reorder the type checks to be on top.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@silverwind
dns: add the 'all' option to dns.lookup
0a914bf
The 'all' option allows to retrieve all addresses returned by
`getaddrinfo` using the system resolver. While `dns.resolve`
already does return multiple results, it's often preferable to
use the system resolver, like for mDNS.
@silverwind
silverwind force-pushed the lookup-multiple branch from f27e8af to 0a914bf Compare February 6, 2015 20:57
@silverwind

silverwind commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

And it's squashed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

Let's see what the CI thinks. https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/154/

I'll do some testing locally too. I don't think the CI runs the internet tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig cjihrig added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 6, 2015
@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

CI seems happy - the FreeBSD and Arm failures are pretty standard. I also ran the Internet tests locally, and they passed. This is a semver minor bump, but that window is already open due to #697.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

Thanks! Landed in eb30009de65a9432b59ae77a425b623df28dbd27 with a tweaked commit message.

EDIT: Someone performed a force push after I landed this. So the mentioned commit was overwritten. The actual commit is now 633a990

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig cjihrig closed this Feb 6, 2015
cjihrig pushed a commit that referenced this pull request Feb 6, 2015
@silverwind @cjihrig
dns: allow dns.lookup() to return all addresses
633a990
This commit adds the 'all' option to dns.lookup(), allowing
all lookup results to be returned.

Semver: Minor
Fixes: #736
PR-URL: #744
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@micnic

micnic commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

@cjihrig, oops, it was me, sorry for that, I edited a wrong commit message

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

@micnic no big deal. It's taken care of.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@silverwind @bnoordhuis @cjihrig @micnic @vkurchatkin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.