I am using the request-promise
module in Node.js to produce lots of parallel requests (>1000), and I am getting the following error after about half of them (500) have completed:
Error: getaddrinfo ENOTFOUND
I saw this github issue: https://github.com/nodejs/node-v0.x-archive/issues/5545 which appears to be my problem, but they never came up with a satisfactory solution. Also, that was for node versions v0.x, while this is occurring in version 5.7.0.
Just for clarity, my requests are approximately the following:
var urls = [];
for(var i=0; i<1000; i++) {
//create url
urls.push(url);
}
return Promise.all(urls.map(createAPIRequestPromise));
where createAPIRequestPromise is essentially:
var rp = require('request-promise');
function createAPIRequestPromise(url) {
var options = {
headers: {
'APIKey': apiKey
},
json: true,
url: url
};
return rp(options);
}
Edit:
Use of promises:
if we let the the first block of code be a function called firerequests
then it looks something like:
firerequests().then(function(bodies){
bodies.forEach(function(body){
console.log(body.valueX);
});
}).catch(function(err){
console.log(err);
});