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

Solve fix inconsistent (hostname vs host) in DNS. #20892 #23572

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ Object.defineProperty(lookup, customPromisifyArgs,
{ value: ['address', 'family'], enumerable: false });


function onlookupservice(err, host, service) {
function onlookupservice(err, hostname, service) {
if (err)
return this.callback(dnsException(err, 'getnameinfo', this.host));
return this.callback(dnsException(err, 'getnameinfo', this.hostname));

this.callback(null, host, service);
this.callback(null, hostname, service);
}


// lookupService(address, port, callback)
function lookupService(host, port, callback) {
function lookupService(hostname, port, callback) {
if (arguments.length !== 3)
throw new ERR_MISSING_ARGS('host', 'port', 'callback');
throw new ERR_MISSING_ARGS('hostname', 'port', 'callback');

if (isIP(host) === 0)
throw new ERR_INVALID_OPT_VALUE('host', host);
if (isIP(hostname) === 0)
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);

if (!isLegalPort(port))
throw new ERR_SOCKET_BAD_PORT(port);
Expand All @@ -175,12 +175,12 @@ function lookupService(host, port, callback) {

var req = new GetNameInfoReqWrap();
req.callback = callback;
req.host = host;
req.hostname = hostname;
Copy link
Member

Choose a reason for hiding this comment

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

Just to understand this: isn't this name used later on during the resolution on the libuv side? And if it's not then what's the use of assigning it here?
/cc @addaleax @jasnell

Copy link
Member

Choose a reason for hiding this comment

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

@lundibundi I think the only use we currently have for it is this.hostname in onlookupservice() above? I might be missing something, though.

Copy link
Member

@lundibundi lundibundi Oct 16, 2018

Choose a reason for hiding this comment

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

Looks like it as I haven't found anything down to the libuv/unix/getnameinfo, though I may have missed it. Though it looks kind of strange that we pass hostname both via req/this and as an argument in case of success.

Well, anyway, CI is almost green so this is fine =).

req.port = port;
req.oncomplete = onlookupservice;

var err = cares.getnameinfo(req, host, port);
if (err) throw dnsException(err, 'getnameinfo', host);
var err = cares.getnameinfo(req, hostname, port);
if (err) throw dnsException(err, 'getnameinfo', hostname);
return req;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,34 @@ function onlookupservice(err, hostname, service) {
this.resolve({ hostname, service });
}

function createLookupServicePromise(host, port) {
function createLookupServicePromise(hostname, port) {
return new Promise((resolve, reject) => {
const req = new GetNameInfoReqWrap();

req.host = host;
req.hostname = hostname;
req.port = port;
req.oncomplete = onlookupservice;
req.resolve = resolve;
req.reject = reject;

const err = getnameinfo(req, host, port);
const err = getnameinfo(req, hostname, port);

if (err)
reject(dnsException(err, 'getnameinfo', host));
reject(dnsException(err, 'getnameinfo', hostname));
});
}

function lookupService(host, port) {
function lookupService(hostname, port) {
if (arguments.length !== 2)
throw new ERR_MISSING_ARGS('host', 'port');
throw new ERR_MISSING_ARGS('hostname', 'port');

if (isIP(host) === 0)
throw new ERR_INVALID_OPT_VALUE('host', host);
if (isIP(hostname) === 0)
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);

if (!isLegalPort(port))
throw new ERR_SOCKET_BAD_PORT(port);

return createLookupServicePromise(host, +port);
return createLookupServicePromise(hostname, +port);
}


Expand Down
6 changes: 3 additions & 3 deletions test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ const mockedErrorCode = 'ENOTFOUND';
const mockedSysCall = 'getaddrinfo';

function errorLookupMock(code = mockedErrorCode, syscall = mockedSysCall) {
return function lookupWithError(host, dnsopts, cb) {
const err = new Error(`${syscall} ${code} ${host}`);
return function lookupWithError(hostname, dnsopts, cb) {
const err = new Error(`${syscall} ${code} ${hostname}`);
err.code = code;
err.errno = code;
err.syscall = syscall;
err.hostname = host;
err.hostname = hostname;
cb(err);
};
}
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ dns.lookup('', {
const err = {
code: 'ERR_MISSING_ARGS',
type: TypeError,
message: 'The "host", "port", and "callback" arguments must be specified'
message: 'The "hostname", "port", and "callback" arguments must be ' +
'specified'
};

common.expectsError(() => dns.lookupService('0.0.0.0'), err);
err.message = 'The "host" and "port" arguments must be specified';
err.message = 'The "hostname" and "port" arguments must be specified';
common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err);
}

Expand All @@ -257,7 +258,7 @@ dns.lookup('', {
const err = {
code: 'ERR_INVALID_OPT_VALUE',
type: TypeError,
message: `The value "${invalidHost}" is invalid for option "host"`
message: `The value "${invalidHost}" is invalid for option "hostname"`
};

common.expectsError(() => {
Expand Down