35

How can I fix below problem? I am using compass.

   Too many open files - Failed to initialize inotify: the user limit on the total number of inotify instances has been reached.
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/rb-inotify-0.9.5/lib/rb-inotify/notifier.rb:64:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapters/linux.rb:66:in `initialize_worker'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:87:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapters/linux.rb:31:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:226:in `works?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:190:in `usable_and_works?'
org/jruby/RubyEnumerable.java:1425:in `all?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:190:in `usable_and_works?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:57:in `select_and_initialize'
org/jruby/RubyArray.java:1613:in `each'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:55:in `select_and_initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:291:in `initialize_adapter'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:283:in `setup'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:65:in `start!'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/sass-3.4.13/lib/sass/plugin/compiler.rb:405:in `listen_to'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/sass-3.4.13/lib/sass/plugin/compiler.rb:338:in `watch'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/compass-1.0.3/lib/compass/sass_compiler.rb:46:in `watch!'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/compass-1.0.3/lib/compass/commands/watch_project.rb:41:in `perform'
file:/home/rmack/Downloads/compass.app/compass-app.jar!/app_watcher.rb:12:in `watch!'
file:/home/rmack/Downloads/compass.app/compass-app.jar!/ui/tray.rb:447:in `watch'
Tombart
  • 30,520
  • 16
  • 123
  • 136
verlager
  • 794
  • 5
  • 25
  • 43

5 Answers5

67

For Linux:

Check current value of max_user_instances:

$ cat /proc/sys/fs/inotify/max_user_instances

increase that value:

$ echo 256 | sudo tee /proc/sys/fs/inotify/max_user_instances

In order to make that change permanent you can always add a line to /etc/sysctl.conf:

fs.inotify.max_user_instances = 256

If your system has a /etc/sysctl.d directory, you would rather put your custom settings in a separate file like /etc/sysctl.d/60-local.conf.

ChrisAga
  • 127
  • 1
  • 9
Tombart
  • 30,520
  • 16
  • 123
  • 136
  • I get `Permission denied`, even when running `sudo echo 256 > /proc/sys/fs/inotify/max_user_instances` (on Debian). The solution of @gcs_dev worked for me (`sudo sh -c ...`) – 0__ Feb 18 '21 at 21:43
  • 2
    That's weird, the command only switches from your current shell (e.g. `bash`) to `sh`. On Debian you could try `sudo sysctl fs.inotify.max_user_instances=256` – Tombart Feb 19 '21 at 09:07
  • hey, @0__ , your sudo isn't working because you're running 'echo 256' as root and then trying to do the redirect as your current user, which cannot write to the target. – Bill McGonigle Mar 31 '22 at 18:31
  • I also got `permission denied` error but I have done the command using `sudo su` and it worked. – Merey Nurlan May 31 '22 at 01:53
  • 1
    To write to the file as root, you need the `sudo` on the second half of the command, the part that is actually doing the write. Instead of `>`, you can use `tee`, and invoke it using `sudo`, like this: `echo 256 | sudo tee /proc/sys/fs/inotify/max_user_instances` – Dave Yarwood Jun 02 '22 at 15:35
  • worked liked a charm. Thanks. I was facing this issue when doing a sbt build in intellij. – Dinesh Raj May 02 '23 at 06:36
6

This is usually a linux config issue. Increase the number of files open in the /etc/security/limits.conf:

It looks like you're using Mac OS in which case you should use sysctl. Add the following to the /etc/sysctl.conf:

kern.maxfiles=your new value kern.maxfilesperproc=your new value
Tombart
  • 30,520
  • 16
  • 123
  • 136
Eric Badiere
  • 182
  • 1
  • 4
4

Solved for me: https://github.com/guard/rb-inotify/issues/23#issuecomment-22997846

# increase inotify file watch limit
ofile=/proc/sys/fs/inotify/max_user_instances
sudo sh -c "echo 8192 > $ofile"
cat $ofile
rerun app.rb
gcs_dev
  • 351
  • 3
  • 7
3

With Ubuntu 22.04, it doesn't work:

sudo sh -c 'echo 256 > /proc/sys/fs/inotify/max_user_instances'

instead must be used this in order to change it temporarily:

sudo sysctl fs.inotify.max_user_instances=8192

It does work what it has been commented previously:

Get current value:

cat /proc/sys/fs/inotify/max_user_instances

In order to save it permanently, add this line:

fs.inotify.max_user_instances = 256

with this command:

sudo vi /etc/sysctl.conf
david.perez
  • 6,090
  • 4
  • 34
  • 57
0

As it is described in other comments, you can try to find application which does not work correctly with the file system.

But in some cases it is alright, only some application (in my case Felix OSGI cache) has too many open files and limits are too low.

Then open /etc/security/limits.conf and add line with limits for the user or group, ie.:

dmatej          soft    nofile          10000
dmatej
  • 1,518
  • 15
  • 24