title: Error: connect ENOBUFS
body: <p>I am writing a little javascript application to test a small HTTP server I wrote using express. The server is working fine, I can make requests to it through a browser, and I can make requests to it through code, but only once. As soon as I perform multiple requests inside a loop, it no longer works as expected. </p>
  
  <p>Here is my little client code:</p>
  
  <pre><code>const http = require('http');
  let alphabet = 'abcdefghijklmnopqrstuvwxyz';
  
  let maxLength = 3;
  
  function permutations(perm, position, string) {
      if (position == perm.length) {
          let username = perm.join('');
          // let url = `http://www.google.com`; // Added this in as a sanity test to check that it is not the server. 
          let url = `http://localhost/${string}${alphabet[i]}`;
          let response = http.get(url, response =&gt; {
              let body = '';
              response.on('data', d =&gt; body += d);
              response.on('end', () =&gt; console.log(`${string}${alphabet[i]}: ${JSON.parse(body).exists}`));
          });
      } else {
          for (let i = 0; i &lt; string.length; i++) {
              perm[position] = string[i];
              permutations(perm, position + 1, string);
          }
      }
  }
  
  for (let length = 1; length &lt;= maxLength; length++) {
      let perm = [];
      for (let i = 0; i &lt; length; i++) {
          perm.push(0);
      }
      permutations(perm, 0, alphabet);
  }
  </code></pre>
  
  <p>Basically this code generates permutations of a certain length made up of letters defined in an alphabet, and sends a request to the server. It should receive a response back inside the callback, but the callback is never called and I get the following error:</p>
  
  <pre><code>Error: connect ENOBUFS 127.0.0.1:80 - Local (undefined:undefined)
      at Object.exports._errnoException (util.js:1029:11)
      at exports._exceptionWithHostPort (util.js:1052:20)
      at connect (net.js:887:16)
      at emitLookup (net.js:1016:7)
      at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:10)
  </code></pre>
  
  <p>However, <code>http.get</code> <em>does</em> work if I put it outside of a loop, the callback gets called, and spits out the results I am looking for (but I need it in a loop). </p>
  
  <p>It also doesn't work if I just try to perform an HTTP <code>GET</code> on a known working server like Google, so I ruled out anything wrong with the server app I wrote. </p>
  
  <p>Why is <code>http.get</code> not performing as expected?</p>
  
  <p>**Update: **</p>
  
  <p>So I tried using <code>agent: false</code> in the <code>options</code> object, and that still didn't work. </p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>To further illustrate the erroneous behavior of nodejs, I have pasted a new version of my server I created for the purpose of this example: </p>
  
  <p>server.js:</p>
  
  <pre><code>var http = require('http');
  
  console.log(new Date(Date.now()).toISOString() + ' ' + 'Starting server...');
  
  http.createServer((req, res) =&gt; {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello!\n');
  
      console.log(new Date(Date.now()).toISOString() + ' ' + 'Responded to request')
  }).listen(8080, '127.0.0.1');
  </code></pre>
  
  <p>However, the server never prints out the expected text when it is responding to a request...</p>