tjfontaine / node-dns

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

Fails when performing too many queries. #110

Closed royalpinto closed 8 years ago

royalpinto commented 8 years ago

Hi,

I trying to resolve around 10240 domains and somehow my script gets completed before completing all the queries. Here is my code:

var query = (function () {

    var dns = require('native-dns');

    var query  = function (domain, callback) {
        var question = dns.Question({
          name: domain,
          type: 'A', // could also be the numerical representation
        });

        var req = dns.Request({
          question: question,
          server: '8.8.8.8',
        });

        req.on('message', callback);

        req.send();

    };
    return query;
})();

//This is just to get 10240 domains
var domains = (function () {
    var udomains = [
        'www.etsy.com',
        'www.ndtv.com',
        'www.akamai.com',
        'www.google.com',
        'www.gmail.com',
        'www.skype.com',
        'www.facebook.com',
        'www.sony.com',
        'www.apple.com',
        'www.hktdc.com',
    ];
    for (var i=0; i< 10; i++) {
        udomains.forEach(function(i) {udomains.push(i);});
    }
    return udomains;
}());

total_domains = domains.length;
console.log('Total domains to be queried:', total_domains);

domains.forEach(function (domain) {
    query(domain, function () {
        console.log('Got a response., Pending: ', total_domains--);
    });
});

Ideally my script should have printed till Got a response., Pending: 0. But it ends somewhere at 10212 (it doesn't end after a fixed number, randomly it ends after some responses). What could be the issue here, am I doing something wrong ?

taoeffect commented 8 years ago

Your issue reminded me to declare the project as needing a new maintainer.

jameshartig commented 8 years ago

I wonder if the problem is actually just that 8.8.8.8 is rate limiting you. Have you tried testing this against a local dns resolver for some domain it can resolve locally (without hitting 8.8.8.8)?

royalpinto commented 8 years ago

Aah..! my bad, I did not realize that there is a separate event for timeout and was not considering it and most of the cases, my request was/is timing out. Sorry :)