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: return real system error instead of 'ENOTFOUND' #5196

Closed
wants to merge 1 commit 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
8 changes: 0 additions & 8 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const net = require('net');
const util = require('util');

const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
const internalNet = require('internal/net');

const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap;
Expand All @@ -16,13 +15,6 @@ const isLegalPort = internalNet.isLegalPort;


function errnoException(err, syscall, hostname) {
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (err === uv.UV_EAI_MEMORY ||
err === uv.UV_EAI_NODATA ||
err === uv.UV_EAI_NONAME) {
err = 'ENOTFOUND';
}
var ex = null;
if (typeof err === 'string') { // c-ares error code.
ex = new Error(syscall + ' ' + err + (hostname ? ' ' + hostname : ''));
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-dns-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function test(mod) {
// Ensure that there is time to attach an error listener.
var req1 = mod.get({host: host, port: 42}, do_not_call);
req1.on('error', common.mustCall(function(err) {
assert.equal(err.code, 'ENOTFOUND');
assert.equal(err.code, 'EAI_NONAME');
}));
// http.get() called req1.end() for us

var req2 = mod.request({method: 'GET', host: host, port: 42}, do_not_call);
req2.on('error', common.mustCall(function(err) {
assert.equal(err.code, 'ENOTFOUND');
assert.equal(err.code, 'EAI_NONAME');
}));
req2.end();
}
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-net-better-error-messages-port-hostname.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ var common = require('../common');
var net = require('net');
var assert = require('assert');

var c = net.createConnection(common.PORT, '...');
var c = net.createConnection(common.PORT, '***');
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for changing ... to ***? (Sorry if it's a naive question.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Trott as I tried to explain in the commit message, the getaddrinfo() error code when hostname is ... is different on different systems:

libc hostname getaddrinfo() error code
glibc ... EAI_NONAME
musl ... EAI_AGAIN
glibc *** EAI_NONAME
musl *** EAI_NONAME

So I changed the hostname instead of testing for both error codes:

 c.on('error', common.mustCall(function(e) {
-  assert.equal(e.code, 'ENOTFOUND');
+  assert(e.code == 'EAI_NONAME' || e.code == 'EAI_AGAIN');
   assert.equal(e.port, common.PORT);

Also, on musl using ... would make the test to wait for a timeoutm while using *** would fail instantly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am open for suggestions for a better commit message.

Copy link
Member

Choose a reason for hiding this comment

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

@ncopa Totally my fault for not reading the commit message before commenting!


c.on('connect', common.fail);

c.on('error', common.mustCall(function(e) {
assert.equal(e.code, 'ENOTFOUND');
assert.equal(e.code, 'EAI_NONAME');
assert.equal(e.port, common.PORT);
assert.equal(e.hostname, '...');
assert.equal(e.hostname, '***');
}));
6 changes: 3 additions & 3 deletions test/parallel/test-net-connect-immediate-finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const common = require('../common');
const assert = require('assert');
const net = require('net');

const client = net.connect({host: '...', port: common.PORT});
const client = net.connect({host: '***', port: common.PORT});

client.once('error', common.mustCall(function(err) {
assert(err);
assert.strictEqual(err.code, err.errno);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.strictEqual(err.code, 'EAI_NONAME');
assert.strictEqual(err.host, err.hostname);
assert.strictEqual(err.host, '...');
assert.strictEqual(err.host, '***');
assert.strictEqual(err.syscall, 'getaddrinfo');
}));

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-net-connect-options-ipv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function tryConnect() {
server.close();
});
}).on('error', function(err) {
if (err.syscall === 'getaddrinfo' && err.code === 'ENOTFOUND') {
if (err.syscall === 'getaddrinfo'
&& (err.code === 'EAI_NODATA' || err.code === 'EAI_NONAME')) {
if (host !== 'localhost' || --localhostTries === 0)
host = hosts[++hostIdx];
if (host)
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-dns-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function do_not_call() {

var socket = net.connect(42, host, do_not_call);
socket.on('error', function(err) {
assert.equal(err.code, 'ENOTFOUND');
assert.equal(err.code, 'EAI_NONAME');
actual_bad_connections++;
});
socket.on('lookup', function(err, ip, type) {
assert(err instanceof Error);
assert.equal(err.code, 'ENOTFOUND');
assert.equal(err.code, 'EAI_NONAME');
assert.equal(ip, undefined);
assert.equal(type, undefined);
});
Expand Down