From 9c684ad2b77ebba1907f47e58c91d9f88a3f3b68 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 9 May 2014 10:28:37 -0700 Subject: [PATCH] core: retry acquire of dotlock [GH-3735] --- CHANGELOG.md | 2 ++ lib/vagrant/environment.rb | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 600487128..4797f41b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ BUG FIXES: - core: Don't lock machines on SSH actions. [GH-3664] - core: Fixed crash when adding a box from Vagrant Cloud that was the same name as a real directory. [GH-3732] + - core: Parallelization is more stable, doesn't crash due to to + bad locks. [GH-3735] - provisioners/shell: Fix shell provisioner config validation when the `binary` option is set to false [GH-3712] - providers/docker: default proxy VM won't use HGFS [GH-3687] diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index afb12f063..91b4486ec 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -403,17 +403,22 @@ module Vagrant lock_path = data_dir.join("lock.#{name}.lock") @logger.debug("Attempting to acquire process-lock: #{name}") - lock("dotlock", noop: name == "dotlock") do + lock("dotlock", noop: name == "dotlock", retry: true) do f = File.open(lock_path, "w+") end # The file locking fails only if it returns "false." If it # succeeds it returns a 0, so we must explicitly check for # the proper error case. - if f.flock(File::LOCK_EX | File::LOCK_NB) === false + while f.flock(File::LOCK_EX | File::LOCK_NB) === false @logger.warn("Process-lock in use: #{name}") - raise Errors::EnvironmentLockedError, - name: name + + if !opts[:retry] + raise Errors::EnvironmentLockedError, + name: name + end + + sleep 0.2 end @logger.info("Acquired process lock: #{name}") @@ -434,7 +439,7 @@ module Vagrant # Clean up the lock file, this requires another lock if name != "dotlock" - lock("dotlock") do + lock("dotlock", retry: true) do f.close File.delete(lock_path) end