title: Node.js socket hang up with http.get but not with request module
body: <p>I am performing some http calls in an AWS lambda. The number of calls are ~400 per minute. 
  The calls are performed as in the following snippet</p>
  
  <pre><code>var req = http.get("https://www.google.com", res =&gt; {
      let body = '';
      res.on('data', chunk =&gt; {
          body += chunk;
      });
      res.on('end', chunk =&gt; {
          if (body.includes('html')) {
              console.log('Got back healthy response');
          } else {
              console.log('Got an unexpected response');
          }
      })
  });
  req.on('error', e =&gt; {
      console.log('Got an error response');
  })
  </code></pre>
  
  <p>That is a simple https request. When the Lambda is invoked, it performs ~40 requests in a single execution.
  My issue is that at the beginning, everything looks good and all the requests are performed correctly. After a while (that can be after ~30 min) calls start to degrade and I get back "socket hang up ECONNRESET" error.</p>
  
  <p>I then tried using the request module and change the code with the following</p>
  
  <pre><code>const request = require('request');
  request("https://www.google.com", function (error, response, body) {
    if (!error &amp;&amp; response.statusCode == 200 &amp;&amp; body.includes('html')) {
      console.log('Got back healthy response' );
    } else {
      console.log('Got an unexpected response');
      console.log('Error: ' + error);
      console.log('Response: ' + response);
      console.log('Body: ' + body);
    }
  });
  </code></pre>
  
  <p>In this case, with the same number of requests within the same lambda, same setting I <em>never</em> get the ECONNRESET error.
  I'm ok using the request module but I'm curious to know why this was happening with the default <code>http</code> implementation.
  Is this caused by socket allocation that the <code>request</code> module handles in a more appropriate way?</p>
  
  <p>I know similar questions have been asked already but I didn't find a good answer for my case.</p>