<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rajat on Medium]]></title>
        <description><![CDATA[Stories by Rajat on Medium]]></description>
        <link>https://medium.com/@confusionprevails?source=rss-3cfbada8715c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7AlYC9AAp1soqAQw.jpg</url>
            <title>Stories by Rajat on Medium</title>
            <link>https://medium.com/@confusionprevails?source=rss-3cfbada8715c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:12:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@confusionprevails/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Living on the ulimit edge — EMFILE, ENFILE exceptions]]></title>
            <link>https://medium.com/2bits/living-on-the-ulimit-edge-961b961e1a0f?source=rss-3cfbada8715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/961b961e1a0f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[unix]]></category>
            <dc:creator><![CDATA[Rajat]]></dc:creator>
            <pubDate>Thu, 27 Oct 2016 20:34:40 GMT</pubDate>
            <atom:updated>2017-01-21T01:17:51.502Z</atom:updated>
            <content:encoded><![CDATA[<p>I am working on a front-end asset and module bundler tool. This tool interacts a lot with the filesystem and reads/writes lots of file.</p><p>And of course it is using Node.js.</p><p>One of the most common exception that I run into is :</p><blockquote>ENFILE: file table overflow, open</blockquote><p>or</p><blockquote>EMFILE, too many open files</blockquote><h3>What is this supposed to be?</h3><p>In simple words — your process is trying to open too many files.</p><p>Unix systems have a configuration that set a limit on maximum number of file descriptors that may be assigned to a process. On OSX this is set to about 256, which is really low, considering the number of files my tool needs to work with.</p><p>These limits on the file descriptors are important because you don’t want a rogue process to open way to many files and eat away all your resources.</p><h3>How to solve this?</h3><p>Let’s start with checking what are the current values imposed by our OS. Open your terminal and run:</p><pre>ulimit -a</pre><p>When I ran this on my Mac, I got:</p><pre>rajatk8SG:~ rajatk$ ulimit -a<br>core file size          (blocks, -c) 0<br>data seg size           (kbytes, -d) unlimited<br>file size               (blocks, -f) unlimited<br>max locked memory       (kbytes, -l) unlimited<br>max memory size         (kbytes, -m) unlimited<br>open files                      (-n) 256<br>pipe size            (512 bytes, -p) 1<br>stack size              (kbytes, -s) 8192<br>cpu time               (seconds, -t) unlimited<br>max user processes              (-u) 709<br>virtual memory          (kbytes, -v) unlimited</pre><p>Do you see open files entry that says 256? That is the limit.</p><p>Now, let us change this to a higher number. To do this, we use terminal again and type:</p><pre>ulimit -n 4096</pre><p>And this should increase the open files!</p><p><strong>Permission Error?</strong></p><p>Well, I have seen that ulimit -n can behave differently on different OSs. It can throw error if increased beyond 1024. The slightly-better solution is to add an entry into .bash_profile or .profile file. That should work.</p><p>Here is my entry on my machines .profile file:</p><pre>ulimit -n 65536 65536</pre><h3>How do I ensure we never run into EMFILE/ENFILE error?</h3><p>In Node.js world, ditch the corefs and use npm module called graceful-fs (<a href="https://github.com/isaacs/node-graceful-fs">here</a>). This module is designed to work with small ulimit values and will never blow up with EMFILE error.</p><p>I hope this was helpful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*U7zx_o0rkhxt5GNUKBfQpg.png" /><figcaption>File Descriptors in Posix</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=961b961e1a0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/2bits/living-on-the-ulimit-edge-961b961e1a0f">Living on the ulimit edge — EMFILE, ENFILE exceptions</a> was originally published in <a href="https://medium.com/2bits">2Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>