title: Can Memory leaks cause getaddrinfo EMFILE
body: <p>I'm having some trouble with my NodeJS API.</p>
  <p>Sometimes, it returns, <code>ConnectionError: getaddrinfo EMFILE</code> and is all is fuc** after this.</p>
  <p>So, I've started to investigate. I found it would be caused by the &quot;to many files descriptors open&quot;. We can apparently increase the number of open files that are authorized but it would not definitely fix the problem.</p>
  <p>I found in <a href="https://glassonionblog.wordpress.com/2013/01/27/increase-ulimit-and-file-descriptors-limit/" rel="nofollow noreferrer">this article</a>, that we can increase the file descriptors settings and the ulimit. But what is the difference?</p>
  <p>Then, to try to isolate my problem, I've run the <code>lsof -i -n -P | grep nodejs</code> command. Indeed, the number of connections established is increasing, so I imagine I have somewhere in my code some connections that are not closed.</p>
  <p>I have some <code>fs.readFileSync</code> and <code>fs.readDirSync</code> etc… but I have not set the <code>autoClose:true</code>. Did you think it would be that?</p>
  <p>Do you have any ideas or advice?</p>
  <p>PS : the App run on a Ubuntu machine</p>
  <hr />
  <p><strong>EDIT , 16-02-2016</strong></p>
  <p>I have ran this command on my production machine <code>lsof -i -n -P | grep nodejs</code></p>
  <p>What I see is something like this:</p>
  <pre><code>...
  nodejs    27596   root  631u  IPv4 109781565      0t0  TCP 127.0.0.1:45268-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  632u  IPv4 109782317      0t0  TCP 172.31.58.93:4242-&gt;172.31.55.229:61616 (ESTABLISHED)
  nodejs    27596   root  633u  IPv4 109779882      0t0  TCP 127.0.0.1:45174-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  634u  IPv4 109779884      0t0  TCP 127.0.0.1:45175-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  635u  IPv4 109781569      0t0  TCP 127.0.0.1:45269-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  636u  IPv4 109781571      0t0  TCP 127.0.0.1:45270-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  637u  IPv4 109782319      0t0  TCP 127.0.0.1:45293-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  642u  IPv4 109781790      0t0  TCP 127.0.0.1:45283-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  643u  IPv4 109781794      0t0  TCP 127.0.0.1:45284-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  644u  IPv4 109781796      0t0  TCP 127.0.0.1:45285-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  645u  IPv4 109781798      0t0  TCP 172.31.58.93:4242-&gt;172.31.55.229:61602 (ESTABLISHED)
  nodejs    27596   root  646u  IPv4 109781800      0t0  TCP 127.0.0.1:45286-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  647u  IPv4 109781802      0t0  TCP 172.31.58.93:4242-&gt;172.31.0.198:1527 (ESTABLISHED)
  nodejs    27596   root  648u  IPv4 109781804      0t0  TCP 127.0.0.1:45287-&gt;127.0.0.1:7272 (ESTABLISHED)
  nodejs    27596   root  649u  IPv4 109781806      0t0  TCP 127.0.0.1:45288-&gt;127.0.0.1:7272 (ESTABLISHED)
  </code></pre>
  <p>But I don't know what it means, do you have any ideas about this?</p>
  <p>Thanks a lot.</p>