tjfontaine / node-dns

Replacement dns module in pure javascript for node.js
MIT License
585 stars 154 forks source link

Errors when using the 1:1 mapping of the upstream node.js dns module combined with the platform object #94

Open mdebruijne opened 9 years ago

mdebruijne commented 9 years ago

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


"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


"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


celesteking commented 9 years ago

To sum it up, this module is not a 1:1 replacement.