Vagrant on The Capitan “Too many open files – getcwd (Errno::EMFILE)”

If you are using vagrant in OSX, with The Capitan, you might experience an issue related with Too many open files. Something like this

[cc lang=”bash” width=”100%”]

==> Destroying VM and associated drives…
/opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/safe_chdir.rb:25:in `chdir’: Too many open files – getcwd (Errno::EMFILE)
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/safe_chdir.rb:25:in `block in safe_chdir’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/safe_chdir.rb:24:in `synchronize’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/safe_chdir.rb:24:in `safe_chdir’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/subprocess.rb:121:in `execute’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/subprocess.rb:22:in `execute’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/base.rb:430:in `block in raw’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/busy.rb:19:in `busy’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/base.rb:429:in `raw’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/base.rb:367:in `block in execute’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/retryable.rb:17:in `retryable’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/base.rb:362:in `execute’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/version_5_0.rb:356:in `read_forwarded_ports’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/version_5_0.rb:635:in `ssh_port’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/provider.rb:76:in `ssh_info’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/machine.rb:425:in `ssh_info’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/communicators/ssh/communicator.rb:319:in `connect’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/communicators/ssh/communicator.rb:64:in `block in wait_for_ready’
from /opt/vagrant/embedded/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout’
from /opt/vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `block in catch’
from /opt/vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch’
from /opt/vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch’
from /opt/vagrant/embedded/lib/ruby/2.2.0/timeout.rb:103:in `timeout’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/communicators/ssh/communicator.rb:42:in `wait_for_ready’
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/action/builtin/wait_for_communicator.rb:16:in `block in call’

[/cc]

This issue is related with a limitation that this version of OSX has, it only allow 256 open files and we need more. An usual value is 1024 so in order to change it an easy way to do it is to add into your .bash_profile or in .zshrc files the command ulimit -n 1024.

Ulimit is a tricky command since only will work in the current shell session, so if you added into your startup shell configuration script you’ll be ok. Keep in mind that once you add the command you need to start a new shell and in the new shell you need to run vagrant up in order to take effect of the change, if you add the command and you are still into a previously opened shell the limit will be 256.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.