For sometime I am having the following error:
Error: EMFILE, too many open files \'/Users/blagus/Gallery/Websites/Nicsware/Pills/resources/core/auth.node.js
This worked for me:
ulimit -n 10480
found here
Check your ulimit. For example initialy my ulimit on OSX was 256.
ulimit -n to see the limit. ulimit -n 1024 to set a higher limit.You can solve this problem by increasing the maxfiles limit:
launchctl limit maxfiles 16384 16384 && ulimit -n 16384
I am using watchman. Which fixed this errors for me. Worth trying!!!
brew update
brew install watchman
ulimit is great if you are using the terminal but it only works if you are running your app from the same terminal tab ( or shell instance ). Launchctl is great but is systemwide. If you leave Launchctl limit maxfile alone, the soft limit is 256 and the hard limit is unlimited.
In a production environment, you will probably need to launch at startup and reboot on crash, which means the best answer for Mac OSX is to use a .plist file for each of your applications. I launch my node application using said plist file ( which runs at start up and reboots after crashing )... inside this file you can set the amount of files per application using the SoftResourcesLimit key.
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>16384</integer>
</dict>
Maximum files was reseted to 256 in OS X 10.10.3 Yosemite. This can lead to problems with npm installations. You can check this limit from terminal with command ulimit -n. In order to change this beyond 256, you need to create two configuration files.
The first property list file /Library/LaunchDaemons/limit.maxfiles.plist :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>65536</string>
<string>65536</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
The second property list file /Library/LaunchDaemons/limit.maxproc.plist :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true />
<key>ServiceIPC</key>
<false />
</dict>
</plist>
Set the proper ownership and rights:
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist
sudo chmod 644 /Library/LaunchDaemons/limit.maxproc.plist
Set the desired limits to bash profile file (.bashrc or .bashprofile or similar):
ulimit -n 65536
ulimit -u 2048
Make sure that the rights are the same for bash profile:
chmod 644 .your_bash_profile_file
Restart computer and check with ulimit -n max files. It should be 65536 and you should be able to change it anything below that.
Source: http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X