Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS error "EMFILE, too many open files" on Mac OS

Tags:

node.js

macos

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'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at Object.Module._extensions..js (module.js:473:44)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at instController  (/Users/blagus/Gallery/Websites/Nicsware/Pills/engine/mvc.node.js:79:31)
    at init (/Users/blagus/Gallery/Websites/Nicsware/Pills/engine/mvc.node.js:57:8)
    at route (/Users/blagus/Gallery/Websites/Nicsware/Pills/engine/dispatcher.node.js:268:36)

The line of code making the call to this file (mvc.node.js:79) is

    this.currentRoute.class = require( controllerFile )[dispatchClass].bind( this );

(it is a framework I am creating)

As you can see, the file auth.node.js is called by a REQUIRE, so the given solutions with gracefullFS and similar does not fit. Besides, this problem occour MacOS only. In a Ubuntu seems to work just fine.

Any thoughts?

like image 743
blagus Avatar asked Nov 14 '13 15:11

blagus


3 Answers

This worked for me:

ulimit -n 10480

found here

like image 200
awongh Avatar answered Oct 22 '22 10:10

awongh


You can solve this problem by increasing the maxfiles limit:

launchctl limit maxfiles 16384 16384 && ulimit -n 16384
like image 49
K M Rakibul Islam Avatar answered Oct 22 '22 10:10

K M Rakibul Islam


i had this error and the ulimit and launchclt didn't work for me,

this solution from http://yabfog.com/blog/2014/10/22/yosemite-upgrade-changes-open-file-limit worked for me

echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
sudo sysctl -w kern.maxfiles=65536
sudo sysctl -w kern.maxfilesperproc=65536
ulimit -n 65536 65536

and then putting the

ulimit -n 65536 65536

into ~/.bashrc

like image 21
aqm Avatar answered Oct 22 '22 09:10

aqm