[Node.js] How to Resolve Error: ENFILE: file table overflow, open xxx

Tadashi Shigeoka ·  Tue, June 26, 2018

I’ll introduce how to resolve the Error: ENFILE: file table overflow, open xxx that occurs in Node.js.

Node.js

Changing the File Descriptor Limit

Error: ENFILE: file table overflow, open xxx is an error that occurs when the file descriptor limit is exceeded.

So the solution is simply to increase the file descriptor limit.

Since the error occurred on macOS this time, I referred to Macのファイルディスクリプタ上限を上げる - 橋本商会 for the solution.

Checking File Descriptors

$ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       709
-n: file descriptors                256

Adding/Updating plist Files

Add/update the following two files in /Library/LaunchDaemons/.

limit.maxfiles.plist

  


  
    Label
    limit.maxfiles
    ProgramArguments
    
      launchctl
      limit
      maxfiles
      524288
      524288
    
    RunAtLoad
    
    ServiceIPC
    
  

limit.maxproc.plist

  


  
    Label
      limit.maxproc
    ProgramArguments
      
        launchctl
        limit
        maxproc
        2048
        2048
      
    RunAtLoad
      
    ServiceIPC
      
  

Change the ownership of the added plist to root.

sudo chown root /Library/LaunchDaemons/limit.max*.plist

Enable the plist settings.

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

Now, restart the OS.

Checking File Descriptors After Changes

ulimit -a  
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       2048
-n: file descriptors                524288

That’s all from the Gemba where I was troubled by the sudden Error: ENFILE: file table overflow, open xxx.