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

dns: enable managing independent channels in JS #14518

Closed
wants to merge 4 commits into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Jul 27, 2017

Fixes: #7231

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes (bonus: make test-internet also passes)
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

dns

CI: https://ci.nodejs.org/job/node-test-commit/11400/
CI: https://ci.nodejs.org/job/node-test-commit/11402/
CI: https://ci.nodejs.org/job/node-test-commit/11404/

@addaleax addaleax added cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. dns Issues and PRs related to the dns subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Jul 27, 2017
@addaleax addaleax requested review from bnoordhuis and XadillaX July 27, 2017 17:38
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jul 27, 2017
doc/api/dns.md Outdated
@@ -54,6 +54,55 @@ dns.resolve4('archive.org', (err, addresses) => {
There are subtle consequences in choosing one over the other, please consult
the [Implementation considerations section][] for more information.

## Class dns.Channel
Copy link
Member Author

Choose a reason for hiding this comment

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

I’d be happy to accept other suggestions for the public name here.

Copy link
Contributor

Choose a reason for hiding this comment

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

dns.Resolver?

Copy link
Member

Choose a reason for hiding this comment

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

Resolver is definitely better, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

@XadillaX @jasnell I agree, renamed to Resolver. :)

: AsyncWrap(channel->env(), req_wrap_obj, AsyncWrap::PROVIDER_QUERYWRAP),
channel_(channel) {
if (env()->in_domain())
req_wrap_obj->Set(env()->domain_string(), env()->domain_array()->Get(0));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This line can segfault, see #14519. As I already stated there, you don't really need to worry about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

It’s not really new code, but yes, I’m changing this to the non-deprecated version of Get so that it “only” crashes.

GetQueryArg());
AresQuery(name,
ns_c_in,
ns_t_any);
Copy link
Member

Choose a reason for hiding this comment

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

This could as well be on one line IMO to be consistent with QueryAWrap::Send etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, that’s an oversight. Updated!

@@ -409,22 +477,53 @@ struct CaresAsyncData {
uv_async_t async_handle;
};

void SetupCaresChannel(Environment* env) {
void ChannelWrap::Setup() {
struct ares_options options;
memset(&options, 0, sizeof(options));
options.flags = ARES_FLAG_NOCHECKRESP;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can add the timeout option here.

Copy link
Contributor

Choose a reason for hiding this comment

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

lib/dns.js Outdated
@@ -263,26 +274,27 @@ function resolver(bindingName) {
req.hostname = name;
req.oncomplete = onresolve;
req.ttl = !!(options && options.ttl);
var err = binding(req, name);
var err = this._handle[bindingName](req, name);
if (err) throw errnoException(err, bindingName);
return req;
};
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make the function anonymous by default then set the name to bindingName before returning...

const fn = (name, /* options, */ callback) => {
  /* ... */
};
fn.name = bindingName
return fn;

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasnell Good idea, done!

lib/dns.js Outdated
function resolver(bindingName) {
var binding = cares[bindingName];
class Channel {
constructor() {
Copy link
Member

Choose a reason for hiding this comment

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

this is optional, but it might be worthwhile allowing the servers to be set here as an optional argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe not in this PR. @XadillaX already mentioned above that there might be other options we could consider adding here, so it seems something to give a little more thought to :)

@addaleax
Copy link
Member Author

doc/api/dns.md Outdated
* [`resolver.resolveTxt()`][`dns.resolveTxt()`]
* [`resolver.reverse()`][`dns.reverse()`]

### channel.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

channel?

Copy link
Member Author

Choose a reason for hiding this comment

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

@XadillaX Thanks for catching this, done!

// Resolver instances correspond 1:1 to c-ares channels.
class Resolver {
constructor() {
this._handle = new ChannelWrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

how about hide _handle via Object.defineProperty?

Copy link
Member Author

Choose a reason for hiding this comment

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

Using a plain _handle property is kind of the standard in Node core. If we were to hide something, I’d suggest thinking of a meaningful custom util.inspect overload for resolvers.

@addaleax
Copy link
Member Author

addaleax commented Aug 1, 2017

One more CI: https://ci.nodejs.org/job/node-test-commit/11484/

I’d like to land if it’s green.

@addaleax
Copy link
Member Author

addaleax commented Aug 1, 2017

Landed in cee8d6d...0f5dabe

@addaleax addaleax closed this Aug 1, 2017
addaleax added a commit that referenced this pull request Aug 1, 2017
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
Ref: #7231
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
This can be used to implement custom timeouts.

Fixes: #7231
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
Ref: #7231
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
This can be used to implement custom timeouts.

Fixes: #7231
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 1, 2017
PR-URL: #14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@addaleax addaleax added the notable-change PRs with changes that should be highlighted in changelogs. label Aug 2, 2017
addaleax added a commit that referenced this pull request Aug 2, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
@addaleax addaleax mentioned this pull request Aug 2, 2017
addaleax added a commit that referenced this pull request Aug 3, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **N-API**
  * Multiple N-API functions for error handling have been changed to support
    assigning error codes.
    [#13988](#13988)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented as an experimental feature.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
addaleax added a commit to addaleax/node that referenced this pull request Aug 4, 2017
This fixes a bug introduced in 727b291
where code managing the `uv_timer_t` for a `ChannelWrap` instance was
left unchanged, when it should have changed the lifetime of the handle
to being tied to the `ChannelWrap` instance’s lifetime.

Fixes: nodejs#14599
Ref: nodejs#14518
addaleax added a commit that referenced this pull request Aug 7, 2017
This fixes a bug introduced in 727b291
where code managing the `uv_timer_t` for a `ChannelWrap` instance was
left unchanged, when it should have changed the lifetime of the handle
to being tied to the `ChannelWrap` instance’s lifetime.

Fixes: #14599
Ref: #14518
PR-URL: #14634
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 7, 2017
This fixes a bug introduced in 727b291
where code managing the `uv_timer_t` for a `ChannelWrap` instance was
left unchanged, when it should have changed the lifetime of the handle
to being tied to the `ChannelWrap` instance’s lifetime.

Fixes: #14599
Ref: #14518
PR-URL: #14634
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax added a commit that referenced this pull request Aug 7, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **N-API**
  * Multiple N-API functions for error handling have been changed to support
    assigning error codes.
    [#13988](#13988)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented as an experimental feature.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
cjihrig pushed a commit that referenced this pull request Aug 8, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **N-API**
  * Multiple N-API functions for error handling have been changed to support
    assigning error codes.
    [#13988](#13988)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented as an experimental feature.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
addaleax added a commit that referenced this pull request Aug 9, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **N-API**
  * Multiple N-API functions for error handling have been changed to support
    assigning error codes.
    [#13988](#13988)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented as an experimental feature.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
  * [gabrielschulhof](https://github.com/gabrielschulhof) – Gabriel Schulhof
cjihrig pushed a commit that referenced this pull request Aug 10, 2017
V8 6.0:

  The V8 engine has been upgraded to version 6.0, which has a significantly
  changed performance profile.
  [#14574](#14574)

  More detailed information on performance differences can be found at
  https://medium.com/the-node-js-collection/get-ready-a-new-v8-is-coming-node-js-performance-is-changing-46a63d6da4de

Other notable changes:

* **DNS**
  * Independent DNS resolver instances are supported now, with support for
    cancelling the corresponding requests.
    [#14518](#14518)

* **N-API**
  * Multiple N-API functions for error handling have been changed to support
    assigning error codes.
    [#13988](#13988)

* **REPL**
  * Autocompletion support for `require()` has been improved.
    [#14409](#14409)

* **Utilities**
  * The WHATWG Encoding Standard (`TextDecoder` and `TextEncoder`) has
    been implemented as an experimental feature.
    [#13644](#13644)

* **Added new collaborators**
  * [XadillaX](https://github.com/XadillaX) – Khaidi Chu
  * [gabrielschulhof](https://github.com/gabrielschulhof) – Gabriel Schulhof

Conflicts:
	src/node_version.h
@gibfahn
Copy link
Member

gibfahn commented Dec 13, 2017

Should land with #17014 if it lands on v6.x.

@gibfahn
Copy link
Member

gibfahn commented Jan 15, 2018

Release team decided not to land on v6.x, if you disagree let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. dns Issues and PRs related to the dns subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants