NodeJS error “EMFILE, too many open files” on Mac OS

后端 未结 11 650
醉话见心
醉话见心 2020-12-22 16:53

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         


        
相关标签:
11条回答
  • 2020-12-22 17:16

    As for other questions about EMFILE error, you have to manage a queue to limit number of files opened at the same time. Increasing limit will only delay your problem.

    There is some responses there : node and Error: EMFILE, too many open files

    0 讨论(0)
  • 2020-12-22 17:18

    awongh's answer worked for me

    ulimit -n 10480
    

    But only after starting an interactive shell

    sudo -i
    

    Outside of the shell I kept getting a permission error on OSX Yosemite

    0 讨论(0)
  • 2020-12-22 17:27

    None of the other answers worked for me. This did the trick:

    launchctl limit maxfiles 16384 16384 
    

    Also to note, this doesn't save across sessions so unless you want to run it for each bash terminal session I suggest putting the above line in your ~/.bashrc (or ~/.zshrc if you are using zsh) by doing this at the command line:

    vi ~/.bashrc
    
    0 讨论(0)
  • 2020-12-22 17:32

    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

    0 讨论(0)
  • 2020-12-22 17:36

    Your code is opening too many files. By default, OS X has a limit of 256 simultaneously opened files. When your code requires a new module, node has to open the file to read it in. If you are already at this limit, node's require cannot continue and will throw an Error. You should audit places in your application where you are calling fs.open and ensuring that you are properly closing all of those files. You may also encounter this problem if you attempt to do too many simultaneous file system reads, since each pending read will be an open file. I have also encountered this problem while using fs.watchFile, which also requires opening a handle to the file.

    0 讨论(0)
提交回复
热议问题