vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

race condition when two Vagrant processes try to download the same box

Open evgeni opened this issue 3 years ago • 0 comments

Vagrant version

2.2.19

Host operating system

CentOS Stream 8 (but shouldn't matter)

Guest operating system

CentOS Stream 8 (but shouldn't matter)

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/stream8"
end

Expected behavior

I have two separate projects that use the same base box (centos/stream8 in this example) in two different folders.

When the base box is not yet available on my system, a vagrant up does download it from the cloud.

As I have two projects, I might call vagrant up in parallel, and expect the two processes not to overwrite each others files and succeed (they will probably download the box twice, but that's OK).

Actual behavior

In reality, if I call vagrant up in parallel for both projects, they both will try to download the box, usually resulting in one of the runs failing, as the one process did overwrite the files of the others:

    /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/file_checksum.rb:47:in `initialize': No such file or directory @ rb_sysopen - /root/.vagrant.d/tmp/boxf4b6e814a5003f4177ccc9098d0df7e64f39b349 (Errno::ENOENT)
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/file_checksum.rb:47:in `open'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/file_checksum.rb:47:in `checksum'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/box_add.rb:554:in `validate_checksum'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/box_add.rb:366:in `box_add'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/box_add.rb:292:in `add_from_metadata'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/box_add.rb:127:in `call'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/warden.rb:48:in `call'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builder.rb:149:in `call'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/runner.rb:89:in `block in run'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/busy.rb:19:in `busy'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/runner.rb:89:in `run'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/handle_box.rb:83:in `handle_box'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/handle_box.rb:42:in `block in call'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/handle_box.rb:36:in `synchronize'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/builtin/handle_box.rb:36:in `call'
            from /opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/action/warden.rb:48:in `call'

Steps to reproduce

  1. copy above Vagrantfile into two folders
  2. call vagrant up in both folders in parallel

evgeni avatar Sep 07 '22 09:09 evgeni