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

后端 未结 11 600
醉话见心
醉话见心 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:09

    This worked for me:

    ulimit -n 10480
    

    found here

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

    Check your ulimit. For example initialy my ulimit on OSX was 256.

    • Run ulimit -n to see the limit.
    • Afterwards You can ulimit -n 1024 to set a higher limit.
    0 讨论(0)
  • 2020-12-22 17:11

    You can solve this problem by increasing the maxfiles limit:

    launchctl limit maxfiles 16384 16384 && ulimit -n 16384
    
    0 讨论(0)
  • 2020-12-22 17:11

    I am using watchman. Which fixed this errors for me. Worth trying!!!

    brew update
    brew install watchman
    
    0 讨论(0)
  • 2020-12-22 17:11

    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>
    
    0 讨论(0)
  • 2020-12-22 17:15

    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

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