node-dns
node-dns copied to clipboard
Errors when using the 1:1 mapping of the upstream node.js dns module combined with the platform object
Hi,
I have noticed multiple errors when using the 1:1 mapping of the upstream node.js dns module combined with the platform object. This is with node version 0.12 and native-dns version 0.7.0.
See below for scripts to reproduce the errors and the output when running these scripts. The only difference between these scripts is the dns.platform.name_servers value.
I think that the scripts and outputs are self-explanatory, but if more information is required then please let me know.
"use strict";
var dns = require("native-dns");
var startTime = process.hrtime();
dns.platform.attempts = 10;
dns.platform.cache = false;
dns.platform.timeout = 500;
dns.platform.name_servers = [
{address: "8.8.4.4", port: 53, type: "udp"},
{address: "8.8.8.8", port: 53, type: "udp"}
];
dns.resolve("www.google.com", "A", function (err, addresses) {
if (err) {
console.log(err);
} else {
console.log(addresses);
}
console.log("Process time: %d seconds", process.hrtime(startTime)[0]);
});
$ time node dns.js
[ '74.125.136.99',
'74.125.136.106',
'74.125.136.103',
'74.125.136.147',
'74.125.136.105',
'74.125.136.104' ]
Process time: 0 seconds
real 0m0.201s
user 0m0.181s
sys 0m0.016s
- expected and current behavior are the same, normal DNS resolving (Baseline)
"use strict";
var dns = require("native-dns");
var startTime = process.hrtime();
dns.platform.attempts = 10;
dns.platform.cache = false;
dns.platform.timeout = 500;
dns.platform.name_servers = [
{address: "127.0.0.1", port: 53, type: "udp"},
{address: "8.8.4.4", port: 53, type: "udp"},
{address: "8.8.8.8", port: 53, type: "udp"}
];
dns.resolve("www.google.com", "A", function (err, addresses) {
if (err) {
console.log(err);
} else {
console.log(addresses);
}
console.log("Process time: %d seconds", process.hrtime(startTime)[0]);
});
$ time node dns.js
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:983:19)
real 0m0.671s
user 0m0.179s
sys 0m0.009s
- expected behavior, go to next server in the array for DNS resolving
- current behavior, throws an error ECONNREFUSED (doesn't return the error object)
- note, in this case DNS Server 127.0.0.1 returns an ICMP Unreachable
"use strict";
var dns = require("native-dns");
var startTime = process.hrtime();
dns.platform.attempts = 10;
dns.platform.cache = false;
dns.platform.timeout = 500;
dns.platform.name_servers = [
{address: "1.1.1.1", port: 53, type: "udp"},
{address: "1.1.1.2", port: 53, type: "udp"}
];
dns.resolve("www.google.com", "A", function (err, addresses) {
if (err) {
console.log(err);
} else {
console.log(addresses);
}
console.log("Process time: %d seconds", process.hrtime(startTime)[0]);
});
$ time node dns.js
{ [Error: getHostByName ETIMEOUT] errno: 'ETIMEOUT', syscall: 'getHostByName' }
Process time: 5 seconds
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:983:19)
real 2m7.993s
user 0m0.223s
sys 0m0.009s
- expected behavior, 10 attempts with 500 ms timeout
- current behavior, 5 attempts with 1000 ms timeout
- note, all values for attempts are divided by two and all values for timeout are multiplied by two (monitored with Wireshark)
- expected behavior, after returning the error object with ETIMEOUT, continue processing
- current behavior, after returning the error object, the process is locked for two minutes and then it throws an error (doesn't return the error object)
- note, these are fake DNS servers and notice that the process time console logged in the script is 5 seconds (as expected), but the total execution time is more than two minutes
To sum it up, this module is not a 1:1 replacement.