From f220bbd9d321d4cb05ac211ebae4f71434c0ac55 Mon Sep 17 00:00:00 2001 From: Yazhong Liu Date: Thu, 7 May 2015 06:49:31 +0800 Subject: [PATCH] dns: make always 8.8.8.8 in name servers this fixes #1644 by always using 8.8.8.8 as one of name servers. --- lib/dns.js | 13 +++++++++++-- test/parallel/test-dns-default-servers.js | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-dns-default-servers.js diff --git a/lib/dns.js b/lib/dns.js index 9334800e4da5c4..e503e13173cc68 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -276,12 +276,12 @@ exports.resolve = function(hostname, type_, callback_) { }; -exports.getServers = function() { +exports.getServers = function getServers() { return cares.getServers(); }; -exports.setServers = function(servers) { +exports.setServers = function setServers(servers) { // cache the original servers because in the event of an error setting the // servers cares won't have any servers available for resolution var orig = cares.getServers(); @@ -353,3 +353,12 @@ exports.NOTINITIALIZED = 'ENOTINITIALIZED'; exports.LOADIPHLPAPI = 'ELOADIPHLPAPI'; exports.ADDRGETNETWORKPARAMS = 'EADDRGETNETWORKPARAMS'; exports.CANCELLED = 'ECANCELLED'; + +// set 8.8.8.8 as default +(function() { + var servers = exports.getServers(); + if (servers.indexOf('8.8.8.8') === -1) { + servers.push('8.8.8.8'); + exports.setServers(servers); + } +})(); diff --git a/test/parallel/test-dns-default-servers.js b/test/parallel/test-dns-default-servers.js new file mode 100644 index 00000000000000..ecd68658282180 --- /dev/null +++ b/test/parallel/test-dns-default-servers.js @@ -0,0 +1,6 @@ +var common = require('../common'); +var assert = require('assert'); +var dns = require('dns'); + +var servers = dns.getServers(); +assert.ok(servers.indexOf('8.8.8.8') !== -1);