title: Error: getaddrinfo ENOTFOUND Node.js request-promise
body: <p>I am using the <code>request-promise</code> 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:</p>
  
  <pre><code>Error: getaddrinfo ENOTFOUND
  </code></pre>
  
  <p>I saw this github issue: <a href="https://github.com/nodejs/node-v0.x-archive/issues/5545" rel="nofollow">https://github.com/nodejs/node-v0.x-archive/issues/5545</a> 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.</p>
  
  <p>Just for clarity, my requests are approximately the following:</p>
  
  <pre><code>var urls = [];
  for(var i=0; i&lt;1000; i++) {
      //create url
      urls.push(url);
  }
  return Promise.all(urls.map(createAPIRequestPromise));
  </code></pre>
  
  <p>where createAPIRequestPromise is essentially:</p>
  
  <pre><code>var rp = require('request-promise');
  function createAPIRequestPromise(url) {
      var options = {
          headers: {
              'APIKey': apiKey
          },
          json: true,
          url: url
      };
      return rp(options);
  }
  </code></pre>
  
  <p>Edit: </p>
  
  <p>Use of promises:
  if we let the the first block of code be a function called <code>firerequests</code> then it looks something like:</p>
  
  <pre><code>firerequests().then(function(bodies){
      bodies.forEach(function(body){
          console.log(body.valueX);
      });
  }).catch(function(err){
      console.log(err);
  });
  </code></pre>